Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
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
2 changes: 1 addition & 1 deletion 2 badges/tests-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion 2 dist/index-browser-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ JSONPath.toPathArray = function (expr) {
return !match || !match[1] ? exp : subx[match[1]];
});
cache[expr] = exprList;
return cache[expr];
return cache[expr].concat();
};

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 2 dist/index-browser-umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@
return !match || !match[1] ? exp : subx[match[1]];
});
cache[expr] = exprList;
return cache[expr];
return cache[expr].concat();
};

/**
Expand Down
2 changes: 1 addition & 1 deletion 2 dist/index-browser-umd.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 2 dist/index-node-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ JSONPath.toPathArray = function (expr) {
return !match || !match[1] ? exp : subx[match[1]];
});
cache[expr] = exprList;
return cache[expr];
return cache[expr].concat();
};

JSONPath.prototype.vm = vm__default['default'];
Expand Down
2 changes: 1 addition & 1 deletion 2 dist/index-node-esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ JSONPath.toPathArray = function (expr) {
return !match || !match[1] ? exp : subx[match[1]];
});
cache[expr] = exprList;
return cache[expr];
return cache[expr].concat();
};

JSONPath.prototype.vm = vm;
Expand Down
2 changes: 1 addition & 1 deletion 2 src/jsonpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ JSONPath.toPathArray = function (expr) {
return !match || !match[1] ? exp : subx[match[1]];
});
cache[expr] = exprList;
return cache[expr];
return cache[expr].concat();
};

export {JSONPath};
15 changes: 15 additions & 0 deletions 15 test/test.toPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ describe('JSONPath - toPath*', function () {

assert.strictEqual(path, originalPath);
});

it('toPathArray (cache issue)', () => {
// We test here a bug where toPathArray did not return a clone of the cached
// array. As a result, the evaluate call corrupted the cached value instead
// of its local copy.

// Make the path unique by including the test name 'cacheissue' in the path
// because we do not want it to be in the cache already.
const expected = ['$', 'store', 'bicycle', 'cacheissue'];
const path = "$.store['bicycle'].cacheissue";
const json = {};
jsonpath({json, path, wrap: false});
const result = jsonpath.toPathArray(path);
assert.deepEqual(result, expected);
});
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.