From 206b6b90b860ceaab58b9bdd5ff20ffc741c13fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 28 Apr 2023 09:49:53 +0000 Subject: [PATCH] fix(core): Fix `hasOwnProperty` on augmented objects (#6124) N8N-6333 Fixes - https://community.n8n.io/t/bug-faulty-javascript-being-implemented-in-the-code-node-after-update-to-v0-222-3/25346 - https://community.n8n.io/t/checking-for-value-in-webhook-body-with-hasownproperty/25068/11 --- packages/workflow/src/AugmentObject.ts | 3 +- packages/workflow/test/AugmentObject.test.ts | 29 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/workflow/src/AugmentObject.ts b/packages/workflow/src/AugmentObject.ts index b05e761a0d..27602b3a23 100644 --- a/packages/workflow/src/AugmentObject.ts +++ b/packages/workflow/src/AugmentObject.ts @@ -143,7 +143,8 @@ export function augmentObject(data: T): T { }, getOwnPropertyDescriptor(target, key) { - return Object.getOwnPropertyDescriptor(data, key) ?? defaultPropertyDescriptor; + if (deletedProperties.indexOf(key) !== -1) return undefined; + return Object.getOwnPropertyDescriptor(key in newData ? newData : data, key); }, }); diff --git a/packages/workflow/test/AugmentObject.test.ts b/packages/workflow/test/AugmentObject.test.ts index 857114a106..dc6f0efd5a 100644 --- a/packages/workflow/test/AugmentObject.test.ts +++ b/packages/workflow/test/AugmentObject.test.ts @@ -528,5 +528,34 @@ describe('AugmentObject', () => { const augmentedObject = augmentObject(originalObject); expect(Object.keys(augmentedObject)).toEqual(['a', 'b']); }); + + test('should return property descriptors', () => { + const originalObject = { + x: { + y: {}, + z: {}, + }, + }; + const augmentedObject = augmentObject(originalObject); + + expect(Object.getOwnPropertyDescriptor(augmentedObject.x, 'y')).toEqual({ + configurable: true, + enumerable: true, + value: {}, + writable: true, + }); + + delete augmentedObject.x.y; + expect(augmentedObject.x.hasOwnProperty('y')).toEqual(false); + + augmentedObject.x.y = 42; + expect(augmentedObject.x.hasOwnProperty('y')).toEqual(true); + expect(Object.getOwnPropertyDescriptor(augmentedObject.x, 'y')).toEqual({ + configurable: true, + enumerable: true, + value: 42, + writable: true, + }); + }); }); });