diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a3daeb..6331e79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +- Fixed `Token::from_encoded` accepting a `~` immediately followed by + another `~` (e.g. `"~~0"`) as valid, letting safe code build a + `PointerBuf` that `Pointer::parse` then rejected on the same bytes. A `~` + must now always be followed by `0` or `1`. Resolves + [#128](https://github.com/chanced/jsonptr/issues/128). + ## [0.8.1] 2026-07-26 ### Added diff --git a/src/token.rs b/src/token.rs index 5d68f34..5aeb0cb 100644 --- a/src/token.rs +++ b/src/token.rs @@ -85,7 +85,7 @@ impl<'a> Token<'a> { source: InvalidEncoding::Slash, }) } - ENC_PREFIX => { + ENC_PREFIX if !escaped => { escaped = true; } TILDE_ENC | SLASH_ENC if escaped => { @@ -575,6 +575,16 @@ mod tests { source: InvalidEncoding::Tilde } ); + // https://github.com/chanced/jsonptr/issues/128 + let err = Token::from_encoded("~~0").unwrap_err(); + assert_eq!( + err, + EncodingError { + offset: 1, + source: InvalidEncoding::Tilde + } + ); + let sub = String::from("a~"); let err = Token::from_encoded(&sub).unwrap_err(); let labels: Vec<_> = err.labels(&sub).unwrap().collect();