diff --git a/src/Merge.ts b/src/Merge.ts index 8df692c..5700dea 100644 --- a/src/Merge.ts +++ b/src/Merge.ts @@ -47,6 +47,7 @@ const handleDefaultBehavior = (originalObject: any, newObject: any, behavior?: if (originalTypeName === "Object" && newTypeName === "Object") { // built-in behavior // tslint:disable:forin for (const p in newObject) { + if (isPrototypePolluted(p)) continue originalObject[p] = processBehavior(originalObject[p], newObject[p], behavior); } // tslint:enable:forin @@ -54,6 +55,10 @@ const handleDefaultBehavior = (originalObject: any, newObject: any, behavior?: } }; +const isPrototypePolluted = (key: any) => { + return ['__proto__', 'constructor', 'prototype'].includes(key) +} + /** * Recursively merge two objects together. * @param originalObject The base object. Properties here will be overwritten @@ -72,7 +77,7 @@ export const Merge = (originalObject: any, newObject: any, behavior?: IMergeBeha return definedBehaviorResults; } } - + return handleDefaultBehavior(originalObject, newObject, behavior); };