Skip to content

Commit b98356f

Browse files
committed
Fix bracketed segments in filter queries [skip ci]
1 parent 2743ee0 commit b98356f

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Fixed normalized paths produced by `JSONPathNode.path()`. Previously we were not handling some escape sequences correctly in name selectors.
88
- Fixed serialization of `JSONPathQuery` instances. `JSONPathQuery.__str__()` now serialized name selectors and string literals to the canonical format, similar to normalized paths. We're also now minimizing the use of parentheses when serializing logical expressions.
9+
- Fixed parsing of filter queries with multiple bracketed segments.
910

1011
## Version 0.1.3
1112

jsonpath_rfc9535/lex.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def ignore_whitespace(self) -> bool:
120120
if self.pos != self.start:
121121
msg = (
122122
"must emit or ignore before consuming whitespace "
123-
f"({self.query[self.start: self.pos]})"
123+
f"({self.query[self.start : self.pos]})"
124124
)
125125
raise JSONPathLexerError(
126126
msg, token=Token(TokenType.ERROR, msg, self.pos, self.query)
@@ -245,8 +245,6 @@ def lex_inside_bracketed_segment(l: Lexer) -> Optional[StateFn]: # noqa: PLR091
245245

246246
if c == "]":
247247
l.emit(TokenType.RBRACKET)
248-
if l.filter_depth:
249-
return lex_inside_filter
250248
return lex_segment
251249

252250
if c == "":

tests/test_parse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ class Case:
136136
query="$[?!(@.a && [email protected])]",
137137
want="$[?!(@['a'] && !@['b'])]",
138138
),
139+
Case(
140+
description="filter query, multiple bracketed segments",
141+
query="$[?@[0][1]]",
142+
want="$[?@[0][1]]",
143+
),
139144
]
140145

141146

0 commit comments

Comments
 (0)