mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Ensure clone methods clone expando properties of boolean, number, & string objects. [closes #2008]
This commit is contained in:
@@ -2318,9 +2318,10 @@
|
||||
return copySymbols(value, baseAssign(result, value));
|
||||
}
|
||||
} else {
|
||||
return cloneableTags[tag]
|
||||
? initCloneByTag(value, tag, isDeep)
|
||||
: (object ? value : {});
|
||||
if (!cloneableTags[tag]) {
|
||||
return object ? value : {};
|
||||
}
|
||||
result = initCloneByTag(value, tag, isDeep);
|
||||
}
|
||||
}
|
||||
// Check for circular references and return its corresponding clone.
|
||||
|
||||
25
test/test.js
25
test/test.js
@@ -813,9 +813,12 @@
|
||||
|
||||
try {
|
||||
var symObject = Object(symbol);
|
||||
|
||||
// Avoid symbol detection in Babel's `typeof` helper.
|
||||
symObject.constructor = Object;
|
||||
|
||||
actual = [
|
||||
Symbol ? lodashBizarro.clone(symObject) : {},
|
||||
Symbol ? lodashBizarro.clone(symObject) : { 'constructor': Object },
|
||||
Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
|
||||
Symbol ? lodashBizarro.toString(symObject) : ''
|
||||
];
|
||||
@@ -823,7 +826,7 @@
|
||||
actual = null;
|
||||
}
|
||||
label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
|
||||
assert.deepEqual(actual, [{}, false, ''], label);
|
||||
assert.deepEqual(actual, [{ 'constructor': Object }, false, ''], label);
|
||||
|
||||
try {
|
||||
var map = new lodashBizarro.memoize.Cache;
|
||||
@@ -2632,6 +2635,24 @@
|
||||
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) {
|
||||
assert.expect(2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user