Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
findNodeAtLocation does not handle incomplete property pair
  • Loading branch information
P0lip committed Feb 19, 2021
commit 7e6ad078fd7a9db42c306871ae8af808aa8a5bcf
2 changes: 1 addition & 1 deletion src/impl/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export function findNodeAtLocation(root: Node | undefined, path: JSONPath): Node
}
let found = false;
for (const propertyNode of node.children) {
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment) {
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
node = propertyNode.children[1];
found = true;
break;
Expand Down
4 changes: 3 additions & 1 deletion src/test/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ suite('JSON', () => {
});

test('tree: find location', () => {
let root = parseTree('{ "key1": { "key11": [ "val111", "val112" ] }, "key2": [ { "key21": false, "key22": 221 }, null, [{}] ] }');
let root = parseTree('{ "key1": { "key11": [ "val111", "val112" ] }, "key2": [ { "key21": false, "key22": 221 }, null, [{}] ], "key3": { "key31":, "key32": 32 } }');
assertNodeAtLocation(root, ['key1'], { key11: ['val111', 'val112'] });
assertNodeAtLocation(root, ['key1', 'key11'], ['val111', 'val112']);
assertNodeAtLocation(root, ['key1', 'key11', 0], 'val111');
Expand All @@ -586,6 +586,8 @@ suite('JSON', () => {
assertNodeAtLocation(root, ['key2', 1], null);
assertNodeAtLocation(root, ['key2', 2], [{}]);
assertNodeAtLocation(root, ['key2', 2, 0], {});
assertNodeAtLocation(root, ['key3', 'key31', 'key311'], undefined);
assertNodeAtLocation(root, ['key3', 'key32'], 32);
});

test('location: matches', () => {
Expand Down