Skip to content

Commit 0d0da8e

Browse files
authored
Fixed incorrect parsing of paren-expression (#33)
* fixed vulnerabilities * Fixed incorrect parsing of paren-expressions (#22)
1 parent a29e14d commit 0d0da8e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Parser.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,10 @@ class TokenParser {
178178
return { type: 'ExpressionReference', child };
179179
}
180180
case Token.TOK_LPAREN: {
181+
console.log('nud::TOK_LPAREN');
181182
const args: ExpressionNode[] = [];
182-
while (this.lookahead(0) !== Token.TOK_RPAREN) {
183-
let expression: ExpressionNode;
184-
if (this.lookahead(0) === Token.TOK_CURRENT) {
185-
expression = { type: Token.TOK_CURRENT };
186-
this.advance();
187-
} else {
188-
expression = this.expression(0);
189-
}
190-
args.push(expression);
191-
}
183+
let expression = this.expression(0);
184+
args.push(expression);
192185
this.match(Token.TOK_RPAREN);
193186
return args[0];
194187
}

test/jmespath-parser.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,14 @@ describe('parsing', () => {
5555
return null;
5656
}, 'syntax');
5757
});
58+
it('should parse paren expression', () => {
59+
// see #22 - issue with parenthesized expression-type
60+
const expected = {
61+
type: 'AndExpression',
62+
left: { type: 'Current' },
63+
right: { type: 'Literal' }
64+
};
65+
expect(compile(' @ && \'truthy\' ')).toMatchObject(expected);
66+
expect(compile('( @ && \'truthy\' )')).toMatchObject(expected);
67+
});
5868
});

0 commit comments

Comments
 (0)