From 117538597c70867c5bd29674e96058162946361a Mon Sep 17 00:00:00 2001 From: Matthias Cremieux <51910570+Mattcrmx@users.noreply.github.com> Date: Wed, 4 Nov 2026 17:56:43 +0100 Subject: [PATCH] fix missing check in strip_prefix --- src/pointer.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pointer.rs b/src/pointer.rs index 887dd49..dcb6b9a 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -287,8 +287,8 @@ impl Pointer { pub fn strip_prefix<'a>(&'a self, prefix: &Self) -> Option<&'a Self> { self.0 .strip_prefix(&prefix.0) - // SAFETY: the suffix is a valid pointer, so removing it from the - // front of another pointer will preserve token boundaries + .filter(|s| s.is_empty() || s.starts_with('/')) + // SAFETY: the remainder is empty or starts at a token boundary .map(|s| unsafe { Self::new_unchecked(s) }) } @@ -1497,6 +1497,12 @@ mod tests { assert_eq!(stripped, "/to/some/value"); } + #[test] + fn strip_prefix_mid_token() { + let p = Pointer::from_static("/fooaƩ/x"); + assert_eq!(p.strip_prefix(Pointer::from_static("/foo")), None); + } + #[test] fn ends_with() { // positive cases