From f311f391532d5cb7ade792cdca0df8f406be4477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Livora?= Date: Fri, 9 Feb 2018 07:28:31 +0100 Subject: [PATCH] fix(Entity): Do not add Array.prototype properties to store --- modules/entity/spec/unsorted_state_adapter.spec.ts | 14 ++++++++++++++ modules/entity/src/unsorted_state_adapter.ts | 5 ++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/entity/spec/unsorted_state_adapter.spec.ts b/modules/entity/spec/unsorted_state_adapter.spec.ts index 0d94a28b2b..40f216e007 100644 --- a/modules/entity/spec/unsorted_state_adapter.spec.ts +++ b/modules/entity/spec/unsorted_state_adapter.spec.ts @@ -11,6 +11,20 @@ describe('Unsorted State Adapter', () => { let adapter: EntityStateAdapter; let state: EntityState; + beforeAll(() => { + Object.defineProperty(Array.prototype, 'unwantedField', { + enumerable: true, + configurable: true, + value: 'This should not appear anywhere', + }); + }); + + afterAll(() => { + Object.defineProperty(Array.prototype, 'unwantedField', { + value: undefined, + }); + }); + beforeEach(() => { adapter = createEntityAdapter({ selectId: (book: BookModel) => book.id, diff --git a/modules/entity/src/unsorted_state_adapter.ts b/modules/entity/src/unsorted_state_adapter.ts index dcf1d53214..72f12585b3 100644 --- a/modules/entity/src/unsorted_state_adapter.ts +++ b/modules/entity/src/unsorted_state_adapter.ts @@ -25,9 +25,8 @@ export function createUnsortedStateAdapter(selectId: IdSelector): any { function addManyMutably(entities: any[], state: any): DidMutate { let didMutate = false; - for (let index in entities) { - didMutate = - addOneMutably(entities[index], state) !== DidMutate.None || didMutate; + for (const entity of entities) { + didMutate = addOneMutably(entity, state) !== DidMutate.None || didMutate; } return didMutate ? DidMutate.Both : DidMutate.None;