mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Ensure has treats nested sparse arrays consistently.
This commit is contained in:
37
lodash.js
37
lodash.js
@@ -5343,29 +5343,24 @@
|
|||||||
* @returns {boolean} Returns `true` if `path` exists, else `false`.
|
* @returns {boolean} Returns `true` if `path` exists, else `false`.
|
||||||
*/
|
*/
|
||||||
function hasPath(object, path, hasFunc) {
|
function hasPath(object, path, hasFunc) {
|
||||||
if (object == null) {
|
path = isKey(path, object) ? [path] : baseCastPath(path);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var result = hasFunc(object, path);
|
|
||||||
if (!result && !isKey(path)) {
|
|
||||||
path = baseCastPath(path);
|
|
||||||
|
|
||||||
var index = -1,
|
var index = -1,
|
||||||
length = path.length;
|
length = path.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var key = path[index];
|
var key = path[index];
|
||||||
if (!(result = object != null && hasFunc(object, key))) {
|
if (!(result = object != null && hasFunc(object, key))) {
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
object = object[key];
|
|
||||||
}
|
}
|
||||||
|
object = object[key];
|
||||||
}
|
}
|
||||||
var length = object ? object.length : undefined;
|
if (result) {
|
||||||
return result || (
|
return result;
|
||||||
!!length && isLength(length) && isIndex(path, length) &&
|
}
|
||||||
(isArray(object) || isString(object) || isArguments(object))
|
var length = object ? object.length : 0;
|
||||||
);
|
return !!length && isLength(length) && isIndex(key, length) &&
|
||||||
|
(isArray(object) || isString(object) || isArguments(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12048,7 +12043,7 @@
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function has(object, path) {
|
function has(object, path) {
|
||||||
return hasPath(object, path, baseHas);
|
return object != null && hasPath(object, path, baseHas);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12078,7 +12073,7 @@
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function hasIn(object, path) {
|
function hasIn(object, path) {
|
||||||
return hasPath(object, path, baseHasIn);
|
return object != null && hasPath(object, path, baseHasIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
12
test/test.js
12
test/test.js
@@ -7243,7 +7243,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('`_.' + methodName + '` should return `true` for index values within bounds for arrays, `arguments` objects, and strings', function(assert) {
|
QUnit.test('`_.' + methodName + '` should return `true` for index values within bounds for arrays, `arguments` objects, and strings', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(2);
|
||||||
|
|
||||||
var string = Object('abc');
|
var string = Object('abc');
|
||||||
delete args[0];
|
delete args[0];
|
||||||
@@ -7256,6 +7256,16 @@
|
|||||||
return func(value, 0);
|
return func(value, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(actual, expected);
|
||||||
|
|
||||||
|
expected = lodashStable.map(values, lodashStable.constant([true, true]));
|
||||||
|
|
||||||
|
actual = lodashStable.map(values, function(value) {
|
||||||
|
return lodashStable.map(['a[0]', ['a', '0']], function(path) {
|
||||||
|
return func({ 'a': value }, path);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
assert.deepEqual(actual, expected);
|
assert.deepEqual(actual, expected);
|
||||||
args[0] = 1;
|
args[0] = 1;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user