Skip to content

Commit

Permalink
Ensure clone methods clone expando properties of boolean, number, & s…
Browse files Browse the repository at this point in the history
…tring objects. [closes #2008]
  • Loading branch information
jdalton committed Feb 17, 2016
1 parent 664d66a commit 7b93dc9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lodash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 23 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,17 +813,20 @@

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) : ''
];
} catch (e) {
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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 7b93dc9

Please sign in to comment.