Skip to content

Commit

Permalink
Merge pull request #37 from flitbit/issue-28-and-30
Browse files Browse the repository at this point in the history
fixes #28 and #30
  • Loading branch information
Phillip Clark committed May 12, 2021
2 parents 434066d + f825bd7 commit 2539e34
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
19 changes: 19 additions & 0 deletions __tests__/ptr.spec.ts
Expand Up @@ -975,6 +975,7 @@ describe('JsonPointer', function () {
});
});
});

describe('when data contains an array early in the path', function () {
const data = {
foo: [] as number[],
Expand Down Expand Up @@ -1022,3 +1023,21 @@ describe('concat pointers', function () {
},
);
});

interface Hacked {
hacked: boolean;
}

describe('path segments containing single quote', function () {
it('issue 28 proof of fix', function () {
expect(JsonPointer.get({}, "/it's bad")).to.eql(undefined);
});
it('issue 30 proof of fix', function () {
JsonPointer.get(
{},
"/aaa'])) !== 'undefined') {return it;}; Number.hacked = true; if(((['a",
);
const result = Number as unknown as Hacked;
expect(result.hacked).to.eql(undefined);
});
});
14 changes: 14 additions & 0 deletions examples/issues/issue-28-PoF.js
@@ -0,0 +1,14 @@
const { JsonPointer } = require('../../dist');
const util = require('util');

var p = new JsonPointer("/I'm/bad");
console.log(util.inspect(p, false, 9));

var a = p.get({}); // expecting this to return undefined
console.log(util.inspect(a, false, 9));

p = new JsonPointer(["I'm", "also", "bad"]);
console.log(util.inspect(p, false, 9));

var a = p.get({}); // expecting this to return undefined
console.log(util.inspect(a, false, 9));
3 changes: 3 additions & 0 deletions examples/issues/issue-30-PoF.js
@@ -0,0 +1,3 @@
const { JsonPointer } = require('../../dist');
JsonPointer.get({},
'/aaa\'\]\)\) !== \'undefined\') \{return it;\}; console.log(\'HACKED\'); if((([\'a'); // HACKED
2 changes: 1 addition & 1 deletion src/util.ts
Expand Up @@ -179,7 +179,7 @@ export function compilePointerDereference(path: PathSegments): Dereference {
return (
body +
" && \n\ttypeof((it = it['" +
replace(path[i] + '', '\\', '\\\\') +
replace(replace(path[i] + '', '\\', '\\\\'), "'", "\\'") +
"'])) !== 'undefined'"
);
}, "if (typeof(it) !== 'undefined'") as string;
Expand Down

0 comments on commit 2539e34

Please sign in to comment.