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 dist/index-browser-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,11 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c
// [name1,name2,...]
const parts = loc.split(',');
for (const part of parts) {
addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback, true));
// 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(prop, x), val, path, parent, parentPropName, callback, true));
}
// simple case--directly follow property
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index-browser-esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-browser-esm.min.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion dist/index-browser-umd.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,11 @@
// [name1,name2,...]
const parts = loc.split(',');
for (const part of parts) {
addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback, true));
// 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(prop, x), val, path, parent, parentPropName, callback, true));
}
// simple case--directly follow property
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index-browser-umd.min.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index-browser-umd.min.cjs.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion dist/index-node-cjs.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,11 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c
// [name1,name2,...]
const parts = loc.split(',');
for (const part of parts) {
addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback, true));
// 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(prop, x), val, path, parent, parentPropName, callback, true));
}
// simple case--directly follow property
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
Expand Down
6 changes: 5 additions & 1 deletion dist/index-node-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,11 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c
// [name1,name2,...]
const parts = loc.split(',');
for (const part of parts) {
addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback, true));
// 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(prop, x), val, path, parent, parentPropName, callback, true));
}
// simple case--directly follow property
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
Expand Down
6 changes: 5 additions & 1 deletion src/jsonpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,12 @@ JSONPath.prototype._trace = function (
} 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), val, path, parent, parentPropName, callback,
unshift(prop, x), val, path, parent, parentPropName, callback,
true
));
}
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