Skip to content

Commit

Permalink
fix(@angular-devkit/core): correctly handle null prototype in deepCopy
Browse files Browse the repository at this point in the history
Closes #19492
  • Loading branch information
alan-agius4 committed Nov 30, 2020
1 parent 064d620 commit 1f42e07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/angular_devkit/core/src/utils/object.ts
Expand Up @@ -40,7 +40,7 @@ export function deepCopy<T extends any>(value: T): T {
return JSON.parse(valueCasted['toJSON']());
}

const copy = new (Object.getPrototypeOf(valueCasted).constructor)();
const copy = Object.create(Object.getPrototypeOf(valueCasted));
valueCasted[copySymbol] = copy;
for (const key of Object.getOwnPropertyNames(valueCasted)) {
copy[key] = deepCopy(valueCasted[key]);
Expand Down
6 changes: 6 additions & 0 deletions packages/angular_devkit/core/src/utils/object_spec.ts
Expand Up @@ -50,5 +50,11 @@ describe('object', () => {
expect(result.b).not.toBe(data1);
expect(result.b).toBe(result.b.circular.b);
});

it('works with null prototype', () => {
const data = Object.create(null);
data['a'] = 1;
expect(deepCopy(data)).toEqual(data);
});
});
});

0 comments on commit 1f42e07

Please sign in to comment.