Skip to content

Commit

Permalink
Refactor to throwForLiteral and update change log
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed May 21, 2024
1 parent d4cb1a6 commit 5f0d234
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# JSON P3 Change Log

## Version 1.3.3 (unreleased)

**Fixes**

- 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).

## Version 1.3.2

**Fixes**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "json-p3",
"version": "1.3.2",
"version": "1.3.3",
"author": "James Prior",
"license": "MIT",
"description": "JSONPath, JSON Pointer and JSON Patch",
Expand Down
30 changes: 12 additions & 18 deletions src/path/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,7 @@ export class Parser {
}
}

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

return keys
? new KeysFilterSelector(
Expand Down Expand Up @@ -397,18 +392,8 @@ export class Parser {
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,
);
}
this.throwForLiteral(left);
this.throwForLiteral(right);
}

return new InfixExpression(tok, left, operator, right);
Expand Down Expand Up @@ -582,4 +567,13 @@ export class Parser {
}
}
}

protected throwForLiteral(expr: FilterExpression): void {
if (expr instanceof FilterExpressionLiteral) {
throw new JSONPathSyntaxError(
`filter expression literals (${expr.toString()}) must be compared`,
expr.token,
);
}
}
}

0 comments on commit 5f0d234

Please sign in to comment.