diff --git a/src/jsonpath.js b/src/jsonpath.js index c9422f4..ed0a19b 100644 --- a/src/jsonpath.js +++ b/src/jsonpath.js @@ -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, diff --git a/test/test.properties.js b/test/test.properties.js index 7201577..44f720e 100644 --- a/test/test.properties.js +++ b/test/test.properties.js @@ -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]]);