Skip to content

Commit

Permalink
Handle filter expression literals without a comparison expression
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed May 20, 2024
1 parent af06a81 commit d4cb1a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/path/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { JSONPathSyntaxError, JSONPathTypeError } from "./errors";
import {
BooleanLiteral,
FilterExpression,
FilterExpressionLiteral,
FunctionExtension,
InfixExpression,
LogicalExpression,
Expand Down Expand Up @@ -330,6 +331,14 @@ export class Parser {
);
}
}

if (expr instanceof FilterExpressionLiteral) {
throw new JSONPathSyntaxError(
"filter expression literals must be compared",
expr.token,
);
}

return keys
? new KeysFilterSelector(
this.environment,
Expand Down Expand Up @@ -387,7 +396,21 @@ export class Parser {
if (COMPARISON_OPERATORS.has(operator)) {
this.throwForNonComparable(left);
this.throwForNonComparable(right);
} else {
if (left instanceof FilterExpressionLiteral) {
throw new JSONPathSyntaxError(
"filter expression literals must be compared",
left.token,
);
}
if (right instanceof FilterExpressionLiteral) {
throw new JSONPathSyntaxError(
"filter expression literals must be compared",
right.token,
);
}
}

return new InfixExpression(tok, left, operator, right);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/path/cts
Submodule cts updated 2 files
+60 −0 cts.json
+60 −0 tests/filter.json

0 comments on commit d4cb1a6

Please sign in to comment.