Skip to content

Commit 78078e4

Browse files
committed
chore: fix edge case regarding forgetting to close a square bracket
1 parent efa70b2 commit 78078e4

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

pkg/jsonpath/parser.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func (p *JSONPath) peek(token token.Token) bool {
6565
return p.current+1 < len(p.tokens) && p.tokens[p.current+1].Token == token
6666
}
6767

68+
// peek returns true if the upcoming token matches the given token type.
69+
func (p *JSONPath) next(token token.Token) bool {
70+
return p.current < len(p.tokens) && p.tokens[p.current].Token == token
71+
}
72+
6873
// expect consumes the current token if it matches the given token type.
6974
func (p *JSONPath) expect(token token.Token) bool {
7075
if p.peek(token) {
@@ -340,7 +345,7 @@ func (p *JSONPath) parseLogicalOrExpr() (*logicalOrExpr, error) {
340345
}
341346
expr.expressions = append(expr.expressions, andExpr)
342347

343-
if p.tokens[p.current].Token != token.OR {
348+
if !p.next(token.OR) {
344349
break
345350
}
346351
p.current++
@@ -359,7 +364,7 @@ func (p *JSONPath) parseLogicalAndExpr() (*logicalAndExpr, error) {
359364
}
360365
expr.expressions = append(expr.expressions, basicExpr)
361366

362-
if p.tokens[p.current].Token != token.AND {
367+
if !p.next(token.AND) {
363368
break
364369
}
365370
p.current++

pkg/jsonpath/parser_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ func TestParserPropertyNameExtension(t *testing.T) {
152152
enabled: false,
153153
valid: false,
154154
},
155+
{
156+
name: "Missing closing a filter expression shouldn't crash",
157+
input: "$.paths.*.*[?([email protected])",
158+
enabled: false,
159+
valid: false,
160+
},
155161
}
156162

157163
for _, test := range tests {

web/src/assets/wasm/lib.wasm

204 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)