Skip to content

Commit

Permalink
chore: fix edge case regarding forgetting to close a square bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRooney committed Jan 24, 2025
1 parent efa70b2 commit 78078e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/jsonpath/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func (p *JSONPath) peek(token token.Token) bool {
return p.current+1 < len(p.tokens) && p.tokens[p.current+1].Token == token
}

// peek returns true if the upcoming token matches the given token type.
func (p *JSONPath) next(token token.Token) bool {
return p.current < len(p.tokens) && p.tokens[p.current].Token == token
}

// expect consumes the current token if it matches the given token type.
func (p *JSONPath) expect(token token.Token) bool {
if p.peek(token) {
Expand Down Expand Up @@ -340,7 +345,7 @@ func (p *JSONPath) parseLogicalOrExpr() (*logicalOrExpr, error) {
}
expr.expressions = append(expr.expressions, andExpr)

if p.tokens[p.current].Token != token.OR {
if !p.next(token.OR) {
break
}
p.current++
Expand All @@ -359,7 +364,7 @@ func (p *JSONPath) parseLogicalAndExpr() (*logicalAndExpr, error) {
}
expr.expressions = append(expr.expressions, basicExpr)

if p.tokens[p.current].Token != token.AND {
if !p.next(token.AND) {
break
}
p.current++
Expand Down
6 changes: 6 additions & 0 deletions pkg/jsonpath/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ func TestParserPropertyNameExtension(t *testing.T) {
enabled: false,
valid: false,
},
{
name: "Missing closing a filter expression shouldn't crash",
input: "$.paths.*.*[?([email protected])",
enabled: false,
valid: false,
},
}

for _, test := range tests {
Expand Down
Binary file modified web/src/assets/wasm/lib.wasm
Binary file not shown.

0 comments on commit 78078e4

Please sign in to comment.