Skip to content

Commit a550f89

Browse files
Eliminate whitespace validation via compound-atomic($) and not-atomics(!) in pest (#100)
thank for the pr
1 parent 2050b61 commit a550f89

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

rfc9535/test_suite/results.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Total; Passed; Failed; Date
99
687; 652; 0; 2025-03-18 22:56:39
1010
687; 652; 0; 2025-03-18 22:57:01
1111
687; 652; 0; 2025-05-13 21:21:59
12+
687; 652; 0; 2025-05-19 15:05:31

src/parser.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@ pub type Parsed<T> = Result<T, JsonPathError>;
2727
///
2828
/// Returns a variant of [crate::JsonPathParserError] if the parsing operation failed.
2929
pub fn parse_json_path(jp_str: &str) -> Parsed<JpQuery> {
30-
if jp_str != jp_str.trim() {
31-
Err(JsonPathError::InvalidJsonPath(
32-
"Leading or trailing whitespaces".to_string(),
33-
))
34-
} else {
35-
JSPathParser::parse(Rule::main, jp_str)
36-
.map_err(Box::new)?
37-
.next()
38-
.ok_or(JsonPathError::UnexpectedPestOutput)
39-
.and_then(next_down)
40-
.and_then(jp_query)
41-
}
30+
JSPathParser::parse(Rule::main, jp_str)
31+
.map_err(Box::new)?
32+
.next()
33+
.ok_or(JsonPathError::UnexpectedPestOutput)
34+
.and_then(next_down)
35+
.and_then(jp_query)
4236
}
4337

4438
pub fn jp_query(rule: Pair<Rule>) -> Parsed<JpQuery> {

src/parser/grammar/json_path_9535.pest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
main = { SOI ~ jp_query ~ EOI }
1+
main = ${ SOI ~ jp_query ~ EOI }
22
jp_query = {root ~ segments}
3-
segments = {(S ~ segment)*}
3+
segments = !{(S ~ segment)*}
44
segment = { child_segment | descendant_segment }
55
child_segment = { bracketed_selection | ("." ~ (wildcard_selector | member_name_shorthand)) }
66
bracketed_selection = { "[" ~ S ~ selector ~ (S ~ "," ~ S ~ selector)* ~ S ~ "]" }

0 commit comments

Comments
 (0)