Skip to content

Commit 5f0d234

Browse files
committed
Refactor to throwForLiteral and update change log
1 parent d4cb1a6 commit 5f0d234

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
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: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,7 @@ export class Parser {
332332
}
333333
}
334334

335-
if (expr instanceof FilterExpressionLiteral) {
336-
throw new JSONPathSyntaxError(
337-
"filter expression literals must be compared",
338-
expr.token,
339-
);
340-
}
335+
this.throwForLiteral(expr);
341336

342337
return keys
343338
? new KeysFilterSelector(
@@ -397,18 +392,8 @@ export class Parser {
397392
this.throwForNonComparable(left);
398393
this.throwForNonComparable(right);
399394
} 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-
}
395+
this.throwForLiteral(left);
396+
this.throwForLiteral(right);
412397
}
413398

414399
return new InfixExpression(tok, left, operator, right);
@@ -582,4 +567,13 @@ export class Parser {
582567
}
583568
}
584569
}
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+
}
585579
}

0 commit comments

Comments
 (0)