Skip to content

Commit 7287c9a

Browse files
authored
Merge pull request #21 from jg-rp/filter-literals
Handle filter expression literals without a comparison expression
2 parents af06a81 + 5f0d234 commit 7287c9a

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# JSON P3 Change Log
22

3+
## Version 1.3.3 (unreleased)
4+
5+
**Fixes**
6+
7+
- Fixed handling of JSONPath filter expression literals. We now throw a `JSONPathSyntaxError` if a filter expression contains a literal (string, int, float, null) that is not part of a comparison or function expression. See [jsonpath-compliance-test-suite #81](https://github.com/jsonpath-standard/jsonpath-compliance-test-suite/pull/81).
8+
39
## Version 1.3.2
410

511
**Fixes**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-p3",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"author": "James Prior",
55
"license": "MIT",
66
"description": "JSONPath, JSON Pointer and JSON Patch",

src/path/parse.ts

Lines changed: 17 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,9 @@ export class Parser {
330331
);
331332
}
332333
}
334+
335+
this.throwForLiteral(expr);
336+
333337
return keys
334338
? new KeysFilterSelector(
335339
this.environment,
@@ -387,7 +391,11 @@ export class Parser {
387391
if (COMPARISON_OPERATORS.has(operator)) {
388392
this.throwForNonComparable(left);
389393
this.throwForNonComparable(right);
394+
} else {
395+
this.throwForLiteral(left);
396+
this.throwForLiteral(right);
390397
}
398+
391399
return new InfixExpression(tok, left, operator, right);
392400
}
393401

@@ -559,4 +567,13 @@ export class Parser {
559567
}
560568
}
561569
}
570+
571+
protected throwForLiteral(expr: FilterExpression): void {
572+
if (expr instanceof FilterExpressionLiteral) {
573+
throw new JSONPathSyntaxError(
574+
`filter expression literals (${expr.toString()}) must be compared`,
575+
expr.token,
576+
);
577+
}
578+
}
562579
}

tests/path/cts

0 commit comments

Comments
 (0)