Skip to content

Commit 2dd768d

Browse files
committed
fix(utils): make clone() only copy own properties
Re: Automattic/mongoose#9876
1 parent bb185d9 commit 2dd768d

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

lib/utils.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ exports.cloneObject = function cloneObject(obj, options) {
6868
var ret = {};
6969
var hasKeys;
7070
var val;
71-
var k;
7271

73-
for (k in obj) {
72+
for (const k of Object.keys(obj)) {
7473
// Not technically prototype pollution because this wouldn't merge properties
7574
// onto `Object.prototype`, but avoid properties like __proto__ as a precaution.
7675
if (specialProperties.indexOf(k) !== -1) {
@@ -295,13 +294,7 @@ exports.isArray = function(arg) {
295294
* Object.keys helper
296295
*/
297296

298-
exports.keys = Object.keys || function(obj) {
299-
var keys = [];
300-
for (var k in obj) if (obj.hasOwnProperty(k)) {
301-
keys.push(k);
302-
}
303-
return keys;
304-
};
297+
exports.keys = Object.keys;
305298

306299
/**
307300
* Basic Object.create polyfill.

0 commit comments

Comments
 (0)