mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 12:27: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));
|
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.
|
||||||
|
|||||||
25
test/test.js
25
test/test.js
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user