mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Ensure _.includes matches an empty string on empty strings. [closes #1275]
This commit is contained in:
@@ -6660,17 +6660,14 @@
|
|||||||
collection = values(collection);
|
collection = values(collection);
|
||||||
length = collection.length;
|
length = collection.length;
|
||||||
}
|
}
|
||||||
if (!length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
|
if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
|
||||||
fromIndex = 0;
|
fromIndex = 0;
|
||||||
} else {
|
} else {
|
||||||
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
||||||
}
|
}
|
||||||
return (typeof collection == 'string' || !isArray(collection) && isString(collection))
|
return (typeof collection == 'string' || !isArray(collection) && isString(collection))
|
||||||
? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)
|
? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
|
||||||
: (getIndexOf(collection, target, fromIndex) > -1);
|
: (!!length && getIndexOf(collection, target, fromIndex) > -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6244,7 +6244,9 @@
|
|||||||
'a string': '1234'
|
'a string': '1234'
|
||||||
},
|
},
|
||||||
function(collection, key) {
|
function(collection, key) {
|
||||||
var values = _.toArray(collection);
|
var isStr = typeof collection == 'string',
|
||||||
|
values = _.toArray(collection),
|
||||||
|
length = values.length;
|
||||||
|
|
||||||
test('should work with ' + key + ' and return `true` for matched values', 1, function() {
|
test('should work with ' + key + ' and return `true` for matched values', 1, function() {
|
||||||
strictEqual(_.includes(collection, 3), true);
|
strictEqual(_.includes(collection, 3), true);
|
||||||
@@ -6263,7 +6265,7 @@
|
|||||||
_.each([4, 6, Math.pow(2, 32), Infinity], function(fromIndex) {
|
_.each([4, 6, Math.pow(2, 32), Infinity], function(fromIndex) {
|
||||||
strictEqual(_.includes(collection, 1, fromIndex), false);
|
strictEqual(_.includes(collection, 1, fromIndex), false);
|
||||||
strictEqual(_.includes(collection, undefined, fromIndex), false);
|
strictEqual(_.includes(collection, undefined, fromIndex), false);
|
||||||
strictEqual(_.includes(collection, '', fromIndex), false);
|
strictEqual(_.includes(collection, '', fromIndex), (isStr && fromIndex == length));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user