diff --git a/src/index.ts b/src/index.ts index 32f6e49..5f258fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,6 +74,9 @@ function _set(value: any, path: Path, object: any): any { let reference = object; parsedPath.forEach((key, index) => { + if (isPrototypePolluted(key)) + return; + if (index === parsedPath.length - 1) { reference[key] = value; return; @@ -89,6 +92,10 @@ function _set(value: any, path: Path, object: any): any { return object; } +function isPrototypePolluted(key: string) { + return ['__proto__', 'constructor', 'prototype'].includes(key); +} + export const get = curry(_get); export const getOr = curry(_getOr); export const has = curry(_has);