Skip to content

Commit

Permalink
Fixed incorrect parsing of paren-expression (#33)
Browse files Browse the repository at this point in the history
* fixed vulnerabilities

* Fixed incorrect parsing of paren-expressions (#22)
  • Loading branch information
springcomp authored Oct 25, 2024
1 parent a29e14d commit 0d0da8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,10 @@ class TokenParser {
return { type: 'ExpressionReference', child };
}
case Token.TOK_LPAREN: {
console.log('nud::TOK_LPAREN');
const args: ExpressionNode[] = [];
while (this.lookahead(0) !== Token.TOK_RPAREN) {
let expression: ExpressionNode;
if (this.lookahead(0) === Token.TOK_CURRENT) {
expression = { type: Token.TOK_CURRENT };
this.advance();
} else {
expression = this.expression(0);
}
args.push(expression);
}
let expression = this.expression(0);
args.push(expression);
this.match(Token.TOK_RPAREN);
return args[0];
}
Expand Down
10 changes: 10 additions & 0 deletions test/jmespath-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,14 @@ describe('parsing', () => {
return null;
}, 'syntax');
});
it('should parse paren expression', () => {
// see #22 - issue with parenthesized expression-type
const expected = {
type: 'AndExpression',
left: { type: 'Current' },
right: { type: 'Literal' }
};
expect(compile(' @ && \'truthy\' ')).toMatchObject(expected);
expect(compile('( @ && \'truthy\' )')).toMatchObject(expected);
});
});

0 comments on commit 0d0da8e

Please sign in to comment.