Ensure _.concat returns an empty array for nullish array values. [closes #1856]

This commit is contained in:
John-David Dalton
2016-01-21 01:13:21 -06:00
parent 345746f7ab
commit 78982f3074
2 changed files with 18 additions and 0 deletions

View File

@@ -5336,6 +5336,9 @@
* // => [1]
*/
var concat = rest(function(array, values) {
if (array == null) {
return [];
}
values = baseFlatten(values);
return arrayConcat(isArray(array) ? array : [Object(array)], values);
});

View File

@@ -2827,6 +2827,21 @@
assert.deepEqual(array, [1]);
});
QUnit.test('should return an empty array when `array` is nullish', function(assert) {
assert.expect(1);
var values = [, null, undefined],
expected = lodashStable.map(values, alwaysEmptyArray);
var actual = lodashStable.map(values, function(value, index) {
try {
return index ? _.concat(value) : _.concat();
} catch (e) {}
});
assert.deepEqual(actual, expected);
});
QUnit.test('should treat sparse arrays as dense', function(assert) {
assert.expect(3);