Skip to content

Commit

Permalink
fix(runtime): invalid splice in ownKeys trap
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed May 15, 2022
1 parent 3ffbc62 commit 1953000
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nimma",
"version": "0.2.0",
"version": "0.2.1",
"description": "Scalable JSONPath engine.",
"keywords": [
"json",
Expand Down
35 changes: 35 additions & 0 deletions src/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,41 @@ describe('Nimma', () => {
});
});

it('works #35', () => {
const document = {
definitions: {
propA: {
properties: {
a: {},
},
},
propB: {
allOf: [
{
properties: {
b: {},
},
},
],
},
},
};

const collected = collect(document, [
'$.definitions.*.properties',
'$.definitions.*.allOf.*.properties',
]);

expect(collected).to.deep.eq({
'$.definitions.*.properties': [
[{ a: {} }, ['definitions', 'propA', 'properties']],
],
'$.definitions.*.allOf.*.properties': [
[{ b: {} }, ['definitions', 'propB', 'allOf', 0, 'properties']],
],
});
});

forEach([
Object.preventExtensions({
shirts: Object.seal({
Expand Down
7 changes: 5 additions & 2 deletions src/runtime/traverse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ const traps = {

const actualKeys = Object.keys(stored);

for (const key of actualKeys) {
for (let i = 0; i < actualKeys.length; i++) {
const key = actualKeys[i];

if (!Object.hasOwnProperty.call(target, key)) {
actualKeys.splice(actualKeys.indexOf(key), 1);
actualKeys.splice(i, 1);
i--;
continue;
}

Expand Down

0 comments on commit 1953000

Please sign in to comment.