Skip to content

Commit cf2f6da

Browse files
committed
Merge pull request #3 from benatkin/complex-keys
Complex keys
2 parents 909456c + 4f23a96 commit cf2f6da

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

jsonpointer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var console = require("console");
22

33
var traverse = function(obj, pointer, value) {
44
// assert(isArray(pointer))
5-
var part = pointer.shift();
5+
var part = unescape(pointer.shift());
66
if(typeof obj[part] !== "undefined") {
77
if(pointer.length == 0) { // we're done
88
if(typeof value !== "undefined") { // set new value, return old value

test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,19 @@ assert.equal(jsonpointer.get(obj, "/d/e/0/a"), 4);
3131
assert.equal(jsonpointer.get(obj, "/d/e/1/b"), 5);
3232
assert.equal(jsonpointer.get(obj, "/d/e/2/c"), 6);
3333

34+
var complexKeys = {
35+
"a/b": {
36+
c: 1
37+
},
38+
d: {
39+
"e/f": 2
40+
}
41+
}
42+
43+
assert.equal(jsonpointer.get(complexKeys, "/a%2Fb/c"), 1);
44+
assert.equal(jsonpointer.get(complexKeys, "/d/e%2Ff"), 2);
45+
assert.throws(function() {
46+
assert.equal(jsonpointer.get(complexKeys, "/a/b/c"), 1);
47+
});
48+
3449
console.log("All tests pass.");

0 commit comments

Comments
 (0)