Regex parentheses escape
catalinstochita opened this issue · comments
catalinstochita commented
Hello. It looks like escaping characters in regex is problematic
#[test]
fn regex_filter_test(){
let json: Box<Value> = Box::new(json!({
"author":"d(Rees)",
}));
let path: Box<JsonPathInst> = Box::from(
JsonPathInst::from_str("$.[?(@.author ~= 'd(Rees)')]").expect("the path is correct"),
);
let finder = JsonPathFinder::new(json.clone(), path);
assert_eq!(finder.find_slice(),vec![Slice(&json!({"author":"d(Rees)",}))]);
}
assertion left == right failed left: [NoValue] right: [Slice(Object {"author": String("d(Rees)")})]
If you try to escape with \ it won't work either
'd\(Rees\)' won't compile, expecting an atom
'd\\(Rees\\)' compiles but it will look for \ in value and () is still treated like a capture group
And if you don't escape the () is considered a capture group
catalinstochita commented
After some testing, looks like we can change the char in .pest to accept it
From
char = _{
!("\"" | "\\" | "\'") ~ ANY
| "\\" ~ ("\"" | "\'" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
To
char = _{
!("\"" | "\\" | "\'") ~ ANY
| "\\" ~ ("\"" | "\'" | "\\" | "/" | "b" | "f" | "n" | "r" | "t" | "(" | ")")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
Boris Zhguchev commented
Hi @catalinstochita ! Thanks for bringing this up.
Yeah, it seems to be a bug in the parser.