8000 Ensure clone methods clone expando properties of boolean, number, & s… · lodash/lodash@3a42318 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a42318

Browse files
committed
Ensure clone methods clone expando properties of boolean, number, & string objects. [closes #2008]
1 parent 664d66a commit 3a42318

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lodash.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,9 +2318,10 @@
23182318
return copySymbols(value, baseAssign(result, value));
23192319
}
23202320
} else {
2321-
return cloneableTags[tag]
2322-
? initCloneByTag(value, tag, isDeep)
2323-
: (object ? value : {});
2321+
if (!cloneableTags[tag]) {
2322+
return object ? value : {};
2323+
}
2324+
result = initCloneByTag(value, tag, isDeep);
23242325
}
23252326
}
23262327
// Check for circular references and return its corresponding clone.

test/test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,17 +813,20 @@
813813

814814
try {
815815
var symObject = Object(symbol);
816+
817+
// Avoid symbol detection in the Babel's `typeof` helper.
816818
symObject.constructor = Object;
819+
817820
actual = [
818-
Symbol ? lodashBizarro.clone(symObject) : {},
821+
Symbol ? lodashBizarro.clone(symObject) : { 'constructor': Object },
819822
Symbol ? lodashBizarro.isEqual(symObject, Object(symbol)) : false,
820823
Symbol ? lodashBizarro.toString(symObject) : ''
821824
];
822825
} catch (e) {
823826
actual = null;
824827
}
825828
label = message('_.clone`, `_.isEqual`, and `_.toString', 'Symbol');
826-
assert.deepEqual(actual, [{}, false, ''], label);
829+
assert.deepEqual(actual, [{ 'constructor': Object }, false, ''], label);
827830

828831
try {
829832
var map = new lodashBizarro.memoize.Cache;
@@ -2632,6 +2635,24 @@
26322635
assert.strictEqual(actual.lastIndex, 3);
26332636
});
26342637

2638+
QUnit.test('`_.' + methodName + '` should clone expando properties', function(assert) {
2639+
assert.expect(1);
2640+
2641+
var values = lodashStable.map([true, false, 1, 'a'], function(value) {
2642+
var object = Object(value);
2643+
object.a = 1;
2644+
return object;
2645+
});
2646+
2647+
var expected = lodashStable.map(values, alwaysTrue);
2648+
2649+
var actual = lodashStable.map(values, function(value) {
2650+
return func(value).a === 1;
2651+
});
2652+
2653+
assert.deepEqual(actual, expected);
2654+
});
2655+
26352656
QUnit.test('`_.' + methodName + '` should clone prototype objects', function(assert) {
26362657
assert.expect(2);
26372658

0 commit comments

Comments
 (0)
0