Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
}

Expand Down Expand Up @@ -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
Expand Down