Skip to content

Fix for issue 102 #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2021
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 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 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 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.

2 changes: 1 addition & 1 deletion 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 dist/index-browser-umd.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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 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 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 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);
});
});