mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Ensure _.concat returns an empty array for nullish array values. [closes #1856]
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
15
test/test.js
15
test/test.js
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user