Skip to content

Commit

Permalink
add isValidKey function to ensure only valid keys are merged
Browse files Browse the repository at this point in the history
  • Loading branch information
doowb committed Jan 4, 2021
1 parent 12cbc0b commit 11e5dd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ node_js:
matrix:
fast_finish: true
allow_failures:
- node_js: 'node'
- node_js: '0.8'
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function mergeDeep(orig, objects) {

function merge(target, obj) {
for (var key in obj) {
if (key === '__proto__' || !hasOwn(obj, key)) {
if (!isValidKey(key) || !hasOwn(obj, key)) {
continue;
}

Expand All @@ -57,3 +57,7 @@ function hasOwn(obj, key) {
function isObject(val) {
return typeOf(val) === 'object' || typeOf(val) === 'function';
}

function isValidKey(key) {
return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';
}

0 comments on commit 11e5dd5

Please # to comment.