Permalink
Browse files

V 0.9

  • Loading branch information...
s3u committed Mar 28, 2012
1 parent 63053e1 commit 35deb4d31f052f667c13f2d63982b8c21c5e1447
Showing with 18 additions and 4 deletions.
  1. +6 −0 CHANGES.md
  2. +11 −3 lib/jsonpath.js
  3. +1 −1 package.json
View
@@ -0,0 +1,6 @@
+
+## Mar 28, 2012
+
+* Support a sandbox arg to eval
+* Use vm.runInNewContext in place of eval
+* Version 0.9.0
View
@@ -4,14 +4,16 @@
* Licensed under the MIT (MIT-LICENSE.txt) licence.
*/
-var _ = require('underscore');
+var vm = require('vm'),
+ _ = require('underscore');
exports.eval = jsonPath;
var cache = {};
function jsonPath(obj, expr, arg) {
var P = {
resultType: arg && arg.resultType || "VALUE",
flatten: arg && arg.flatten || false,
wrap: (arg && arg.hasOwnProperty('wrap')) ? arg.wrap : true,
+ sandbox: (arg && arg.sandbox) ? arg.sandbox : {},
normalize: function(expr) {
if(cache[expr]) {
return cache[expr];
@@ -110,8 +112,14 @@ function jsonPath(obj, expr, arg) {
}
},
eval: function(x, _v, _vname) {
- try { return $ && _v && eval(x.replace(/@/g, "_v")); }
- catch(e) { throw new SyntaxError("jsonPath: " + e.message + ": " + x.replace(/@/g, "_v").replace(/\^/g, "_a")); }
+ P.sandbox["_v"] = _v;
+ try {
+ return $ && _v && vm.runInNewContext(x.replace(/@/g, "_v"), P.sandbox);
+ }
+ catch(e) {
+ console.log(e);
+ throw new SyntaxError("jsonPath: " + e.message + ": " + x.replace(/@/g, "_v").replace(/\^/g, "_a"));
+ }
}
};
P.result = P.wrap === true ? [] : undefined;
View
@@ -16,7 +16,7 @@
"email": "mike@brevoort.com"
}
],
- "version": "0.8.6",
+ "version": "0.9.0",
"repository": {
"type": "git",
"url": "git://github.com/s3u/JSONPath.git"

0 comments on commit 35deb4d

Please sign in to comment.