mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
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
This commit is contained in:
parent
5974af1903
commit
206b6b90b8
|
@ -143,7 +143,8 @@ export function augmentObject<T extends object>(data: T): T {
|
||||||
},
|
},
|
||||||
|
|
||||||
getOwnPropertyDescriptor(target, key) {
|
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);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -528,5 +528,34 @@ describe('AugmentObject', () => {
|
||||||
const augmentedObject = augmentObject(originalObject);
|
const augmentedObject = augmentObject(originalObject);
|
||||||
expect(Object.keys(augmentedObject)).toEqual(['a', 'b']);
|
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,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue