Skip to content

Commit 70232bb

Browse files
Copilotdayongkr
andcommitted
Add test for circular references in null prototype objects
Co-authored-by: dayongkr <[email protected]>
1 parent e833a07 commit 70232bb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/compat/object/cloneDeepWith.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,16 @@ describe('cloneDeepWith', function () {
174174
expect(cloned.a).toBe(2);
175175
expect(cloned.b).toBe(4);
176176
});
177+
178+
it('should handle circular references in objects with null prototype', () => {
179+
const obj: any = Object.create(null);
180+
obj.a = 1;
181+
obj.self = obj; // circular reference
182+
183+
const cloned = cloneDeepWith(obj);
184+
185+
expect(Object.getPrototypeOf(cloned)).toBe(Object.prototype);
186+
expect(cloned.self).toBe(cloned);
187+
expect(cloned.a).toBe(1);
188+
});
177189
});

0 commit comments

Comments
 (0)