Skip to content

Commit 1c00347

Browse files
authored
Merge pull request #35 from jg-rp/fix-filter-queries
Fix parsing of filter queries
2 parents 5f12cd1 + 6e05215 commit 1c00347

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-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 2.1.1 (unreleased)
4+
5+
**Fixes**
6+
7+
- Fixed parsing of filter queries containing multiple consecutive bracketed segments. Previously we were failing to parse queries like `$[?@[0][1]]`.
8+
39
## Version 2.1.0
410

511
**Changes**

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": "2.1.0",
3+
"version": "2.1.1",
44
"author": "James Prior",
55
"license": "MIT",
66
"description": "JSONPath, JSON Pointer and JSON Patch",

src/path/lex.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ function lexInsideBracketedSelection(l: Lexer): StateFn | null {
392392
switch (ch) {
393393
case "]":
394394
l.emit(TokenKind.RBRACKET);
395-
if (l.filterLevel) return lexInsideFilter;
396395
return lexSegment;
397396
case "":
398397
l.error("unclosed bracketed selection");

tests/path/parse.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ const TEST_CASES: TestCase[] = [
3737
path: "$[?@.* && @.b]",
3838
want: "$[?@[*] && @.b]",
3939
},
40+
{
41+
description: "filter query, multiple shorthand segments",
42+
path: "$[?@.a.b.c]",
43+
want: "$[?@.a.b.c]",
44+
},
45+
{
46+
description: "filter query, multiple bracketed segments",
47+
path: "$[?@[0][1] && $[2][3]]",
48+
want: "$[?@[0][1] && $[2][3]]",
49+
},
50+
{
51+
description: "filter query, dotted and bracketed segments",
52+
path: "$[?@.a[1][2] && $.b[2].c[3]]",
53+
want: "$[?@.a[1][2] && $.b[2].c[3]]",
54+
},
4055
];
4156

4257
describe("parse", () => {

0 commit comments

Comments
 (0)