fix: Docpath join was escaping *
@@ -171,7 +171,11 @@ impl DocPath {
pub fn join(&self, field: impl Into<String>) -> Self {
let field = field.into();
let mut path = self.clone();
+ if field == "*" {
+ path.push_star();
+ } else {
path.push_field(field);
+ }
path
}
@@ -723,4 +727,13 @@ mod tests {
assert_eq!(obj_key_for_path(r#"a'"#), r#"['a\'']"#);
assert_eq!(obj_key_for_path(r#"\"#), r#"['\\']"#);
}
+
+ #[test]
+ fn path_join() {
+ let something = DocPath::root().join("something");
+ expect!(something.to_string()).to(be_equal_to("$.something"));
+ expect!(DocPath::root().join("something else").to_string()).to(be_equal_to("$['something else']"));
+ expect!(something.join("else").to_string()).to(be_equal_to("$.something.else"));
+ expect!(something.join("*").to_string()).to(be_equal_to("$.something.*"));
+ }
}
