Extended `util.parsePath` with support for all '*'
This commit is contained in:
parent
f0afcea97d
commit
8f7b656c3c
|
@ -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 {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Reference in New Issue