diff --git a/src/js/util.js b/src/js/util.js index c7c8fa7..aa384ea 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -658,7 +658,8 @@ exports.parsePath = function parsePath(jsonPath) { throw new SyntaxError('Index expected after ['); } - prop = JSON.parse(jsonPath.substring(1, end)); + var value = jsonPath.substring(1, end); + prop = value === '*' ? value : JSON.parse(value); // parse string and number remainder = jsonPath.substr(end + 1); } else { diff --git a/test/util.test.js b/test/util.test.js index 2549545..8ae25c2 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -1,6 +1,9 @@ var assert = require('assert'); var util = require('../src/js/util'); +// console.log('TEST', util.parsePath('.items[3].name')); +// console.log('TEST', util.parsePath('.items[*].name')); + describe('util', function () { describe('sanitize', function () { @@ -70,6 +73,7 @@ describe('util', function () { assert.deepEqual(util.parsePath('.foo[2]'), ['foo', 2]); assert.deepEqual(util.parsePath('.foo[2].bar'), ['foo', 2, 'bar']); assert.deepEqual(util.parsePath('.foo["prop with spaces"]'), ['foo', 'prop with spaces']); + assert.deepEqual(util.parsePath('.foo[*].bar'), ['foo', '*', 'bar']); }); it ('should throw an exception in case of an invalid path', function () {