From 2f9bab74939ff70f7ef67188b6e06b1b7be2220d Mon Sep 17 00:00:00 2001 From: lukas-eu <62448426+lukas-eu@users.noreply.github.com> Date: Wed, 22 Jul 2026 17:08:44 +0200 Subject: [PATCH 1/2] Block traversal to global method instances --- pointer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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} } From 30e174b33db03ebe041117bb4afdb44491e797dc Mon Sep 17 00:00:00 2001 From: lukas-eu <62448426+lukas-eu@users.noreply.github.com> Date: Wed, 22 Jul 2026 17:10:02 +0200 Subject: [PATCH 2/2] Adding test --- test/issues.ts | 9 +++++++++ 1 file changed, 9 insertions(+) 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') +})