Ensure clone methods clone expando properties of boolean, number, & string objects. [closes #2008]

This commit is contained in:
John-David Dalton
2016-02-16 20:39:44 -08:00
parent 664d66a89e
commit 7b93dc9c32
2 changed files with 27 additions and 5 deletions

View File

@@ -2318,9 +2318,10 @@
return copySymbols(value, baseAssign(result, value)); return copySymbols(value, baseAssign(result, value));
} }
} else { } else {
return cloneableTags[tag] if (!cloneableTags[tag]) {
? initCloneByTag(value, tag, isDeep) return object ? value : {};
: (object ? value : {}); }
result = initCloneByTag(value, tag, isDeep);
} }
} }
// Check for circular references and return its corresponding clone. // Check for circular references and return its corresponding clone.

View File

@@ -813,9 +813,12 @@
try { try {
var symObject = Object(symbol); var symObject = Object(symbol);
// Avoid symbol detection in Babel's `typeof` helper.
symObject.constructor = Object; symObject.constructor = Object;
actual = [ actual = [
Symbol ? lodashBizarro.clone(symObject) : {}, Symbol ? lodashBizarro.clone(symObject) : { 'constructor': Object },
Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false, Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
Symbol ? lodashBizarro.toString(symObject) : '' Symbol ? lodashBizarro.toString(symObject) : ''
]; ];
@@ -823,7 +826,7 @@
actual = null; actual = null;
} }
label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol'); label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
assert.deepEqual(actual, [{}, false, ''], label); assert.deepEqual(actual, [{ 'constructor': Object }, false, ''], label);
try { try {
var map = new lodashBizarro.memoize.Cache; var map = new lodashBizarro.memoize.Cache;
@@ -2632,6 +2635,24 @@
assert.strictEqual(actual.lastIndex, 3); assert.strictEqual(actual.lastIndex, 3);
}); });
QUnit.test('`_.' + methodName + '` should clone expando properties', function(assert) {
assert.expect(1);
var values = lodashStable.map([true, false, 1, 'a'], function(value) {
var object = Object(value);
object.a = 1;
return object;
});
var expected = lodashStable.map(values, alwaysTrue);
var actual = lodashStable.map(values, function(value) {
return func(value).a === 1;
});
assert.deepEqual(actual, expected);
});
QUnit.test('`_.' + methodName + '` should clone prototype objects', function(assert) { QUnit.test('`_.' + methodName + '` should clone prototype objects', function(assert) {
assert.expect(2); assert.expect(2);