Skip to content

Commit

Permalink
ensure keys are valid
Browse files Browse the repository at this point in the history
  • Loading branch information
doowb committed Jun 25, 2019
1 parent 24412bd commit 8e3cc4a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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`
*/
Expand Down

0 comments on commit 8e3cc4a

Please # to comment.