There was an error while loading. Please reload this page.
parser(@)
1 parent ba96548 commit 3d1a14aCopy full SHA for 3d1a14a
2 files changed
lib/jsonpath.js
@@ -351,9 +351,9 @@ JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropN
351
this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));
352
code = code.replace(/@path/g, '_$_path');
353
}
354
- if (code.match(/@([\.\s\[])/)) {
+ if (code.match(/@([\.\s\)\[])/)) {
355
this.currSandbox._$_v = _v;
356
- code = code.replace(/@([\.\s\[])/g, '_$_v$1');
+ code = code.replace(/@([\.\s\)\[])/g, '_$_v$1');
357
358
try {
359
return vm.runInNewContext(code, this.currSandbox);
test/test.eval.js
@@ -51,7 +51,20 @@ module.exports = testCase({
51
var result = jsonpath({
52
json: json,
53
sandbox: {category: 'reference'},
54
- path: "$..[?(@.category == category)]", wrap: false
+ path: "$..[?(@.category === category)]", wrap: false
55
+ });
56
+ test.deepEqual(expected, result);
57
+ test.done();
58
+ },
59
+
60
+ 'sandbox (with parsing function)': function (test) {
61
+ var expected = json.store.book;
62
+ var result = jsonpath({
63
+ json: json,
64
+ sandbox: {filter: function (arg) {
65
+ return arg.category === 'reference';
66
+ }},
67
+ path: "$..[?(filter(@))]", wrap: false
68
});
69
test.deepEqual(expected, result);
70
test.done();
0 commit comments