diff --git a/pointer.ts b/pointer.ts index 9b794c5..84b9d6f 100644 --- a/pointer.ts +++ b/pointer.ts @@ -72,8 +72,10 @@ export class Pointer { if (key == '__proto__' || key == 'constructor' || key == 'prototype') { continue } - // not sure if this the best way to handle non-existant paths... - value = (parent || {})[key] + value = undefined + if (parent && Object.prototype.hasOwnProperty.call(parent, key)) { + value = parent[key] + } } return {parent, key, value} } diff --git a/test/issues.ts b/test/issues.ts index 86f1191..74ef486 100644 --- a/test/issues.ts +++ b/test/issues.ts @@ -280,3 +280,12 @@ test('minimal array diff', t => { ] checkRoundtrip(t, input, output, expected_patch) }) + +test('issues/2ndopp', t => { + t.true(({} as any).polluted === undefined, 'toString function should not be polluted') + const value = {} + applyPatch(value, [ + {op: 'add', path: '/toString/polluted', value: 'Hello!'} + ]) + t.true(({} as any).toString.polluted === undefined, 'toString function should still not be polluted') +})