Skip to content

Commit

Permalink
Fix lexer error message from unclosed filter expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed Mar 22, 2024
1 parent 6c45e8b commit b3d5657
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ benchmark/*.txt

# dev
tests/dev.test.ts
dev.js
dev.mjs
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.1.2 (unreleased)

**Fixes**

- Fixed the error and error message arising from JSONPath queries with filter expressions and a missing closing bracket for the segment. Previously we would get a `JSONPathLexerError`, stating we "can't backup beyond start", which is meant to be an internal error. We now get a `JSONPathSyntaxError` with the message "unclosed bracketed selection".

## Version 1.1.1

**Fixes**
Expand Down
2 changes: 2 additions & 0 deletions src/path/lex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ function lexInsideFilter(l: Lexer): StateFn | null {
const ch = l.next();
switch (ch) {
case "":
l.error("unclosed bracketed selection");
return null;
case "]":
l.filterLevel -= 1;
if (l.parenStack.length === 1) {
Expand Down
11 changes: 11 additions & 0 deletions tests/path/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,14 @@ describe("recursion limit reached", () => {
);
});
});

describe("filter expression EOF", () => {
const env = new JSONPathEnvironment();
test("unclosed bracketed selection", () => {
const query = "$.users[[email protected] > 85";
expect(() => env.query(query, {})).toThrow(JSONPathSyntaxError);
expect(() => env.query(query, {})).toThrow(
"unclosed bracketed selection ('core > 85':21)",
);
});
});

0 comments on commit b3d5657

Please sign in to comment.