From 11e5dd56de8a6aed0b1ed022089dbce6968d82a5 Mon Sep 17 00:00:00 2001 From: Brian Woodward Date: Mon, 4 Jan 2021 14:21:09 -0500 Subject: [PATCH] add isValidKey function to ensure only valid keys are merged --- .travis.yml | 1 + index.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b41bd9f..ea3ec10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,5 @@ node_js: matrix: fast_finish: true allow_failures: + - node_js: 'node' - node_js: '0.8' diff --git a/index.js b/index.js index 16b4690..08db87a 100644 --- a/index.js +++ b/index.js @@ -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; } @@ -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'; +} \ No newline at end of file