diff --git a/source/internal/_clone.js b/source/internal/_clone.js index 5de62403f..0f92875be 100644 --- a/source/internal/_clone.js +++ b/source/internal/_clone.js @@ -30,7 +30,7 @@ export default function _clone(value, deep, map) { map.set(value, copiedValue); for (var key in value) { - if (value.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(value, key)) { copiedValue[key] = deep ? _clone(value[key], true, map) : value[key]; } } @@ -83,7 +83,7 @@ _ObjectMap.prototype.set = function(key, value) { _ObjectMap.prototype.hash = function(key) { let hashedKey = []; for (var value in key) { - hashedKey.push(key[value]); + hashedKey.push(Object.prototype.toString.call(key[value])); } return hashedKey.join(); }; diff --git a/test/clone.js b/test/clone.js index 5817f68c4..b4674a3a4 100644 --- a/test/clone.js +++ b/test/clone.js @@ -299,6 +299,19 @@ describe('deep clone edge cases', function() { }); +describe('clone objects with no prototypes', function() { + it('nested object with no prototype', function() { + const obj = Object.create(null); + obj.intValue = 1; + obj.a = Object.create(null); + obj.a.stringValue = 'Yeah'; + const clonedObj = R.clone(obj); + assert.strictEqual(Object.getPrototypeOf(clonedObj), null); + assert.strictEqual(Object.getPrototypeOf(clonedObj.a), null); + assert.strictEqual(clonedObj.intValue, 1); + assert.strictEqual(clonedObj.a.stringValue, 'Yeah'); + }); +}); describe('Let `R.clone` use an arbitrary user defined `clone` method', function() {