Skip to content

Commit 8e3cc4a

Browse files
committed
ensure keys are valid
1 parent 24412bd commit 8e3cc4a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function extend(target, obj) {
3737
assignSymbols(target, obj);
3838

3939
for (var key in obj) {
40-
if (key !== '__proto__' && hasOwn(obj, key)) {
40+
if (isValidKey(key) && hasOwn(obj, key)) {
4141
var val = obj[key];
4242
if (isObject(val)) {
4343
if (typeOf(target[key]) === 'undefined' && typeOf(val) === 'function') {
@@ -68,6 +68,14 @@ function hasOwn(obj, key) {
6868
return Object.prototype.hasOwnProperty.call(obj, key);
6969
}
7070

71+
/**
72+
* Returns true if the given `key` is a valid key that can be used for assigning properties.
73+
*/
74+
75+
function isValidKey(key) {
76+
return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';
77+
}
78+
7179
/**
7280
* Expose `assign`
7381
*/

0 commit comments

Comments
 (0)