From 90ee1fab375fccfd9b926df718243339b4976d50 Mon Sep 17 00:00:00 2001 From: doowb Date: Mon, 24 Jun 2019 16:31:42 -0400 Subject: [PATCH] ensure keys are valid when mixing in values --- index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 909fbef..47face2 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ function mixinDeep(target, objects) { */ function copy(val, key) { - if (key === '__proto__') { + if (!isValidKey(key)) { return; } @@ -46,6 +46,17 @@ function isObject(val) { return isExtendable(val) && !Array.isArray(val); } +/** + * Returns true if `key` is a valid key to use when extending objects. + * + * @param {String} `key` + * @return {Boolean} + */ + +function isValidKey(key) { + return key !== '__proto__' && key !== 'constructor' && key !== 'prototype'; +}; + /** * Expose `mixinDeep` */