Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/jsonpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,12 @@ class JSONPathClass {
} else if (loc.includes(',')) { // [name1,name2,...]
const parts = loc.split(',');
for (const part of parts) {
// Strip the quotes that survive tokenization of a quoted union
// member (e.g. $['x','y'] leaves parts ["x'", "'y"]); bare and
// numeric members have no quotes and are unaffected.
const prop = part.trim().replace(/^['"]|['"]$/gu, '');
addRet(this._trace(
unshift(part, x),
unshift(prop, x),
val,
path,
parent,
Expand Down
7 changes: 7 additions & 0 deletions test/test.properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ checkBuiltInVMAndNodeVM(function (vmType, setBuiltInState) {
assert.deepEqual(result, expected);
});

it('Union of quoted property names', () => {
const data = {x: 1, y: 2, z: 3};
assert.deepEqual(jsonpath({json: data, path: "$['x','y']"}), [1, 2]);
assert.deepEqual(jsonpath({json: data, path: '$["x","y"]'}), [1, 2]);
assert.deepEqual(jsonpath({json: data, path: "$['x', 'y']"}), [1, 2]);
});

it('At signs within properties', () => {
let result = jsonpath({json, path: "$.datafield[?(@.tag=='035')]", wrap: false});
assert.deepEqual(result, [json.datafield[0]]);
Expand Down