Permalink
Browse files

Merge pull request #3 from benatkin/complex-keys

Complex keys
  • Loading branch information...
2 parents 909456c + 4f23a96 commit cf2f6da24d2bfbba13dda2f0b0b6ffa6346dbf47 @janl committed Jul 31, 2011
Showing with 16 additions and 1 deletion.
  1. +1 −1 jsonpointer.js
  2. +15 −0 test.js
View
2 jsonpointer.js
@@ -2,7 +2,7 @@ var console = require("console");
var traverse = function(obj, pointer, value) {
// assert(isArray(pointer))
- var part = pointer.shift();
+ var part = unescape(pointer.shift());
if(typeof obj[part] !== "undefined") {
if(pointer.length == 0) { // we're done
if(typeof value !== "undefined") { // set new value, return old value
View
15 test.js
@@ -31,4 +31,19 @@ assert.equal(jsonpointer.get(obj, "/d/e/0/a"), 4);
assert.equal(jsonpointer.get(obj, "/d/e/1/b"), 5);
assert.equal(jsonpointer.get(obj, "/d/e/2/c"), 6);
+var complexKeys = {
+ "a/b": {
+ c: 1
+ },
+ d: {
+ "e/f": 2
+ }
+}
+
+assert.equal(jsonpointer.get(complexKeys, "/a%2Fb/c"), 1);
+assert.equal(jsonpointer.get(complexKeys, "/d/e%2Ff"), 2);
+assert.throws(function() {
+ assert.equal(jsonpointer.get(complexKeys, "/a/b/c"), 1);
+});
+
console.log("All tests pass.");

0 comments on commit cf2f6da

Please sign in to comment.