mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-19 16:55:02 +02:00
Co-authored-by: Charlie Kolb <charlie@n8n.io> Co-authored-by: Guillaume Jacquart <jacquart.guillaume@gmail.com> Co-authored-by: Stephen Wright <sjw948@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Bernhard Wittmann <bernhard.wittmann@n8n.io> Co-authored-by: Nikhil Kuriakose <nikhil.kuriakose@n8n.io> Co-authored-by: Albert Alises <albert.alises@gmail.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Andreas Fitzek <andreas.fitzek@n8n.io> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: Robin Braumann <50590409+bjorger@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: yehorkardash <yehor.kardash@n8n.io> Co-authored-by: Mike Repeć <mike.repec@n8n.io> Co-authored-by: Yuliia Pominchuk <31064937+yuliia-pominchuk@users.noreply.github.com> Co-authored-by: RomanDavydchuk <roman.davydchuk@n8n.io>
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import set from 'lodash/set';
|
|
|
|
// Guards the lodash@4.18.1 patch (patches/lodash@4.18.1.patch): while walking a
|
|
// dot-notation path, `baseSet` reuses the value already present at a segment only
|
|
// when it is an own property, otherwise it creates a fresh object. A segment that
|
|
// matches an inherited member is therefore stored as plain own data instead of
|
|
// being followed onto an object shared through the prototype chain. These tests
|
|
// fail if the patch is ever dropped (e.g. on a lodash bump).
|
|
describe('lodash/set patch', () => {
|
|
const originalToStringCall = Object.prototype.toString.call;
|
|
afterEach(() => {
|
|
Object.prototype.toString.call = originalToStringCall;
|
|
});
|
|
|
|
it('writes a top-level built-in-named segment as own data', () => {
|
|
const obj: Record<string, unknown> = {};
|
|
set(obj, 'toString.call', 'x');
|
|
|
|
// Read the global into a local and restore it before any expect(), since
|
|
// expect()/toEqual themselves use Object.prototype.toString.call.
|
|
const callType = typeof Object.prototype.toString.call;
|
|
Object.prototype.toString.call = originalToStringCall;
|
|
|
|
expect(callType).toBe('function');
|
|
expect(obj).toEqual({ toString: { call: 'x' } });
|
|
});
|
|
|
|
it('writes a nested built-in-named segment as own data', () => {
|
|
const obj: Record<string, unknown> = {};
|
|
set(obj, 'a.toString.call', 'x');
|
|
|
|
const callType = typeof Object.prototype.toString.call;
|
|
Object.prototype.toString.call = originalToStringCall;
|
|
|
|
expect(callType).toBe('function');
|
|
expect(obj).toEqual({ a: { toString: { call: 'x' } } });
|
|
});
|
|
|
|
it('preserves normal and array paths', () => {
|
|
const obj: Record<string, unknown> = {};
|
|
set(obj, 'a.b.c', 1);
|
|
set(obj, 'list[0].name', 'n');
|
|
|
|
expect(obj).toEqual({ a: { b: { c: 1 } }, list: [{ name: 'n' }] });
|
|
});
|
|
});
|