Skip to content

Fix Token::from_encoded accepting a double tilde - #129

Merged
asmello merged 1 commit into
mainfrom
fix/128-token-double-tilde
Aug 20, 2026
Merged

Fix Token::from_encoded accepting a double tilde#129
asmello merged 1 commit into
mainfrom
fix/128-token-double-tilde

Conversation

@asmello

@asmello asmello commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Token::from_encoded set escaped = true unconditionally when it saw ~, so a second ~ right after an already-open escape (e.g. the second ~ in "~~0") was treated as re-opening the escape rather than being rejected as an invalid escape sequence.
  • This let safe code (Token::from_encodedPointerBuf::from_tokens) construct a PointerBuf whose string form Pointer::parse then refused on the exact same bytes.
  • Fix: only transition into the escaped state when not already escaped; a ~ seen while already escaped now falls through to the existing "invalid character after tilde" error path.

Fixes #128

Test plan

  • Added a regression test in src/token.rs asserting Token::from_encoded("~~0") returns EncodingError { offset: 1, source: InvalidEncoding::Tilde }
  • cargo test --all-features (105 lib tests + 49 doc tests) passes
  • cargo clippy --all-features --all-targets is clean

The escaped-tilde branch set `escaped = true` unconditionally, so a
`~` following an already-open escape (e.g. the second `~` in "~~0")
was treated as re-opening the escape instead of being rejected. This
let safe code build a PointerBuf via Token::from_encoded that
Pointer::parse then refused on the same bytes.

Fixes #128
@asmello
asmello merged commit a9b704d into main Aug 20, 2026
21 checks passed
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.6%. Comparing base (3dc1604) to head (d7d933e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Δ
src/token.rs 98.4% <100.0%> (+<0.1%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@asmello asmello mentioned this pull request Aug 20, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Token::from_encoded accepts a double tilde, building an invalid pointer

2 participants