Skip to content

Commit d4cb1a6

Browse files
committed
Handle filter expression literals without a comparison expression
1 parent af06a81 commit d4cb1a6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/path/parse.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { JSONPathSyntaxError, JSONPathTypeError } from "./errors";
33
import {
44
BooleanLiteral,
55
FilterExpression,
6+
FilterExpressionLiteral,
67
FunctionExtension,
78
InfixExpression,
89
LogicalExpression,
@@ -330,6 +331,14 @@ export class Parser {
330331
);
331332
}
332333
}
334+
335+
if (expr instanceof FilterExpressionLiteral) {
336+
throw new JSONPathSyntaxError(
337+
"filter expression literals must be compared",
338+
expr.token,
339+
);
340+
}
341+
333342
return keys
334343
? new KeysFilterSelector(
335344
this.environment,
@@ -387,7 +396,21 @@ export class Parser {
387396
if (COMPARISON_OPERATORS.has(operator)) {
388397
this.throwForNonComparable(left);
389398
this.throwForNonComparable(right);
399+
} else {
400+
if (left instanceof FilterExpressionLiteral) {
401+
throw new JSONPathSyntaxError(
402+
"filter expression literals must be compared",
403+
left.token,
404+
);
405+
}
406+
if (right instanceof FilterExpressionLiteral) {
407+
throw new JSONPathSyntaxError(
408+
"filter expression literals must be compared",
409+
right.token,
410+
);
411+
}
390412
}
413+
391414
return new InfixExpression(tok, left, operator, right);
392415
}
393416

tests/path/cts

0 commit comments

Comments
 (0)