Skip to content

Commit 2539e34

Browse files
author
Phillip Clark
authored
Merge pull request #37 from flitbit/issue-28-and-30
fixes #28 and #30
2 parents 434066d + f825bd7 commit 2539e34

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

__tests__/ptr.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ describe('JsonPointer', function () {
975975
});
976976
});
977977
});
978+
978979
describe('when data contains an array early in the path', function () {
979980
const data = {
980981
foo: [] as number[],
@@ -1022,3 +1023,21 @@ describe('concat pointers', function () {
10221023
},
10231024
);
10241025
});
1026+
1027+
interface Hacked {
1028+
hacked: boolean;
1029+
}
1030+
1031+
describe('path segments containing single quote', function () {
1032+
it('issue 28 proof of fix', function () {
1033+
expect(JsonPointer.get({}, "/it's bad")).to.eql(undefined);
1034+
});
1035+
it('issue 30 proof of fix', function () {
1036+
JsonPointer.get(
1037+
{},
1038+
"/aaa'])) !== 'undefined') {return it;}; Number.hacked = true; if(((['a",
1039+
);
1040+
const result = Number as unknown as Hacked;
1041+
expect(result.hacked).to.eql(undefined);
1042+
});
1043+
});

examples/issues/issue-28-PoF.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { JsonPointer } = require('../../dist');
2+
const util = require('util');
3+
4+
var p = new JsonPointer("/I'm/bad");
5+
console.log(util.inspect(p, false, 9));
6+
7+
var a = p.get({}); // expecting this to return undefined
8+
console.log(util.inspect(a, false, 9));
9+
10+
p = new JsonPointer(["I'm", "also", "bad"]);
11+
console.log(util.inspect(p, false, 9));
12+
13+
var a = p.get({}); // expecting this to return undefined
14+
console.log(util.inspect(a, false, 9));

examples/issues/issue-30-PoF.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { JsonPointer } = require('../../dist');
2+
JsonPointer.get({},
3+
'/aaa\'\]\)\) !== \'undefined\') \{return it;\}; console.log(\'HACKED\'); if((([\'a'); // HACKED

src/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export function compilePointerDereference(path: PathSegments): Dereference {
179179
return (
180180
body +
181181
" && \n\ttypeof((it = it['" +
182-
replace(path[i] + '', '\\', '\\\\') +
182+
replace(replace(path[i] + '', '\\', '\\\\'), "'", "\\'") +
183183
"'])) !== 'undefined'"
184184
);
185185
}, "if (typeof(it) !== 'undefined'") as string;

0 commit comments

Comments
 (0)