From 2dd768d66904a6ad11c7e1a9aa210710aecdbaf7 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 12 Feb 2021 12:04:52 -0500 Subject: [PATCH] fix(utils): make clone() only copy own properties Re: Automattic/mongoose#9876 --- lib/utils.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index fba56c8..c738f0e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -68,9 +68,8 @@ exports.cloneObject = function cloneObject(obj, options) { var ret = {}; var hasKeys; var val; - var k; - for (k in obj) { + for (const k of Object.keys(obj)) { // Not technically prototype pollution because this wouldn't merge properties // onto `Object.prototype`, but avoid properties like __proto__ as a precaution. if (specialProperties.indexOf(k) !== -1) { @@ -295,13 +294,7 @@ exports.isArray = function(arg) { * Object.keys helper */ -exports.keys = Object.keys || function(obj) { - var keys = []; - for (var k in obj) if (obj.hasOwnProperty(k)) { - keys.push(k); - } - return keys; -}; +exports.keys = Object.keys; /** * Basic Object.create polyfill.