From 8e3cc4a34246733672c71e96532105384937e56c Mon Sep 17 00:00:00 2001 From: doowb Date: Tue, 25 Jun 2019 13:46:37 -0400 Subject: [PATCH] ensure keys are valid --- index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c5dc494..7b45f0c 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,7 @@ function extend(target, obj) { assignSymbols(target, obj); for (var key in obj) { - if (key !== '__proto__' && hasOwn(obj, key)) { + if (isValidKey(key) && hasOwn(obj, key)) { var val = obj[key]; if (isObject(val)) { if (typeOf(target[key]) === 'undefined' && typeOf(val) === 'function') { @@ -68,6 +68,14 @@ function hasOwn(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); } +/** + * Returns true if the given `key` is a valid key that can be used for assigning properties. + */ + +function isValidKey(key) { + return key !== '__proto__' && key !== 'constructor' && key !== 'prototype'; +} + /** * Expose `assign` */