Skip to content

Commit 7849f70

Browse files
committed
Fixing support for sandbox in the case of functions;
update CHANGES; Lint JS test support files; Split out tests into `eslint`, `remark`, `lint`, `nodeunit`; Add remark linting to testing process (JSONPath-Plus#70); bump to 0.15.0
1 parent 352bf41 commit 7849f70

File tree

3 files changed

+53
-28
lines changed

3 files changed

+53
-28
lines changed

CHANGES.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
# JSONPath changes
22

3-
## Unreleased
4-
5-
- Use `this` if present for global export
6-
7-
## Jan 10, 2016
3+
## 0.15.0 (Mar 15, 2016)
4+
5+
- Fix: Fixing support for sandbox in the case of functions
6+
- Feature: Use `this` if present for global export
7+
- Docs: Clarify function signature
8+
- Docs: Update testing section
9+
- Dev testing: Add in missing test for browser testing
10+
- Dev testing: Add remark linting to testing process (#70)
11+
- Dev testing: Lint JS test support files
12+
- Dev testing: Split out tests into `eslint`, `remark`, `lint`, `nodeunit`
13+
- Dev testing: Remove need for nodeunit build step
14+
- Dev testing: Simplify nodeunit usage and make available
15+
as `npm run browser-test`
16+
17+
## 0.14.0 (Jan 10, 2016)
818

919
- Add `@scalar()` type operator (in JavaScript mode, will also include)
10-
- Version 0.14.0
1120

12-
## Jan 5, 2016
21+
## 0.13.1 (Jan 5, 2016)
1322

1423
- Avoid double-encoding path in results
15-
- Version 0.13.1
1624

17-
## Dec 13, 2015
25+
## 0.13.0 (Dec 13, 2015)
1826

1927
- Breaking change (from version 0.11): Silently strip `~` and `^` operators
2028
and type operators such as `@string()` in `JSONPath.toPathString()` calls.
@@ -27,32 +35,28 @@
2735
- Fix: Enhance Node checking to avoid issue reported with angular-mock
2836
- Fix: Allow for `@` or other special characters in at-sign-prefixed
2937
property names (by use of `[?(@['...'])]` or `[(@['...'])]`).
30-
- Version 0.13.0
3138

32-
## Dec 12, 2015 10:39pm
39+
## 0.12.0 (Dec 12, 2015 10:39pm)
3340

3441
- Breaking change: Problems with upper-case letters in npm is causing
3542
us to rename the package, so have renamed package to "jsonpath-plus"
3643
(there are already package with lower-case "jsonpath" or "json-path").
3744
The new name also reflects that there have been changes to the
3845
original spec.
39-
- Version 0.12.0
4046

41-
## Dec 12, 2015 10:36pm
47+
## 0.11.2 (Dec 12, 2015 10:36pm)
4248

4349
- Actually add the warning in the README that problems in npm
4450
with upper-case letters is causing us to rename to "jsonpath-plus"
4551
(next version will actually apply the change).
46-
- Version 0.11.2
4752

48-
## Dec 12, 2015 10:11pm
53+
## 0.11.1 (Dec 12, 2015 10:11pm)
4954

5055
- Give warning in README that problems in npm with upper-case letters
5156
is causing us to rename to "jsonpath-plus" (next version will actually
5257
apply the change).
53-
- Version 0.11.1
5458

55-
## Dec 12, 2015
59+
## 0.11.0 (Dec 12, 2015)
5660

5761
- Breaking change: For unwrapped results, return `undefined` instead
5862
of `false` upon failure to find path (to allow distinguishing of
@@ -92,18 +96,15 @@
9296
- Fix: Allow `^` as property name
9397
- Fix: Support `.` within properties
9498
- Fix: `@path` in index/property evaluations
95-
- Version 0.11
9699

97-
## Oct 23, 2013
100+
## 0.10.0 (Oct 23, 2013)
98101

99102
- Support for parent selection via `^`
100103
- Access current path via `@path` in test statements
101104
- Allowing for multi-statement evals
102105
- Performance improvements
103-
- Version 0.10
104106

105-
## Mar 28, 2012
107+
## 0.9.0 (Mar 28, 2012)
106108

107109
- Support a sandbox arg to eval
108110
- Use vm.runInNewContext in place of eval
109-
- Version 0.9.0

lib/jsonpath.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,33 @@ var isNode = module && !!module.exports;
1515

1616
var allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all'];
1717

18+
var moveToAnotherArray = function (source, target, conditionCb) {
19+
for (var i = 0, kl = source.length; i < kl; i++) {
20+
var key = source[i];
21+
if (conditionCb(key)) {
22+
target.push(source.splice(i--, 1)[0]);
23+
}
24+
}
25+
};
26+
1827
var vm = isNode
1928
? require('vm') : {
2029
runInNewContext: function (expr, context) {
21-
return eval(Object.keys(context).reduce(function (s, vr) {
30+
var keys = Object.keys(context);
31+
var funcs = [];
32+
moveToAnotherArray(keys, funcs, function (key) {
33+
return typeof context[key] === 'function';
34+
});
35+
var code = funcs.reduce(function (s, func) {
36+
return 'var ' + func + '=' + context[func].toString() + ';' + s;
37+
}, '');
38+
code += keys.reduce(function (s, vr) {
2239
return 'var ' + vr + '=' + JSON.stringify(context[vr]).replace(/\u2028|\u2029/g, function (m) {
2340
// http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
2441
return '\\u202' + (m === '\u2028' ? '8' : '9');
2542
}) + ';' + s;
26-
}, expr));
43+
}, expr);
44+
return eval(code);
2745
}
2846
};
2947

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030
],
3131
"license": "MIT",
32-
"version": "0.14.0",
32+
"version": "0.15.0",
3333
"repository": {
3434
"type": "git",
3535
"url": "git://github.com/s3u/JSONPath.git"
@@ -45,14 +45,20 @@
4545
"eslint": "^1.10.3",
4646
"eslint-config-standard": "^4.4.0",
4747
"eslint-plugin-standard": "^1.3.1",
48-
"nodeunit": "0.9.0"
48+
"nodeunit": "0.9.0",
49+
"remark-lint": "^3.0.0",
50+
"remark": "^4.1.2"
4951
},
5052
"keywords": [
5153
"json",
5254
"jsonpath"
5355
],
5456
"scripts": {
55-
"test": "./node_modules/.bin/eslint test lib && \"./node_modules/.bin/nodeunit\" test",
56-
"browser-test": "node ./test-helpers/nodeunit-server"
57+
"eslint": "./node_modules/.bin/eslint test lib test-helpers",
58+
"remark": "./node_modules/.bin/remark -q -f .",
59+
"lint": "npm run eslint && npm run remark",
60+
"nodeunit": "./node_modules/.bin/nodeunit test",
61+
"test": "npm run lint && npm run nodeunit",
62+
"browser-test": "npm run lint && node ./test-helpers/nodeunit-server"
5763
}
5864
}

0 commit comments

Comments
 (0)