Skip to content

Commit

Permalink
fix edge case caught by quicktest
Browse files Browse the repository at this point in the history
  • Loading branch information
asmello committed Mar 31, 2024
1 parent 2878e62 commit f25c0bf
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@ impl Pointer {
}
idx += 1;
}
Self::new(&self.0[..idx])
if idx == self.0.len() || self.0.as_bytes()[idx] == b'/' {
Self::new(&self.0[..idx])
} else {
Self::new(&self.0[..last_slash])
}
}

/// Attempts to delete a `serde_json::Value` based upon the path in this
Expand Down Expand Up @@ -1572,6 +1576,11 @@ mod tests {
let a = Pointer::from_static("/foo/bar/qux");
let b = Pointer::from_static("/foo/bar");
assert_eq!(a.intersection(b), base);

let base = Pointer::from_static("");
let a = Pointer::from_static("/foo");
let b = Pointer::from_static("/");
assert_eq!(a.intersection(b), base);
}

#[test]
Expand Down

0 comments on commit f25c0bf

Please sign in to comment.