From f25c0bf0b1f100ac7e620b4e2d525d09af2aa5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1=20de=20Mello?= <3285133+asmello@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:44:22 +0100 Subject: [PATCH] fix edge case caught by quicktest --- src/pointer.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pointer.rs b/src/pointer.rs index 2e8f1f5..0d8c510 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -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 @@ -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]