mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Ensure _.has treats sparse arrays as dense.
This commit is contained in:
@@ -9715,13 +9715,18 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var result = hasOwnProperty.call(object, path);
|
var result = hasOwnProperty.call(object, path);
|
||||||
if (!result && !isKey(path)) {
|
if (result) {
|
||||||
path = toPath(path);
|
return result;
|
||||||
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
|
||||||
path = last(path);
|
|
||||||
result = object != null && hasOwnProperty.call(object, path);
|
|
||||||
}
|
}
|
||||||
return result || (lodash.support.nonEnumStrings && isString(object) && isIndex(path, object.length));
|
if (isKey(path)) {
|
||||||
|
var length = object.length;
|
||||||
|
return isLength(length) &&
|
||||||
|
(isArray(object) || (support.nonEnumStrings && isString(object)) ||
|
||||||
|
(support.nonEnumArgs && isArguments(object))) && isIndex(path, length);
|
||||||
|
}
|
||||||
|
path = toPath(path);
|
||||||
|
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
||||||
|
return object != null && hasOwnProperty.call(object, last(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
12
test/test.js
12
test/test.js
@@ -6248,6 +6248,8 @@
|
|||||||
QUnit.module('lodash.has');
|
QUnit.module('lodash.has');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
var args = arguments;
|
||||||
|
|
||||||
test('should check for own properties', 2, function() {
|
test('should check for own properties', 2, function() {
|
||||||
var object = { 'a': 1 };
|
var object = { 'a': 1 };
|
||||||
|
|
||||||
@@ -6311,6 +6313,14 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should treat sparse arrays as dense', 1, function() {
|
||||||
|
strictEqual(_.has(Array(1), 0), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should work with `arguments` objects', 1, function() {
|
||||||
|
strictEqual(_.has(args, 1), true);
|
||||||
|
});
|
||||||
|
|
||||||
test('should check for a key over a path', 2, function() {
|
test('should check for a key over a path', 2, function() {
|
||||||
var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
|
var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
|
||||||
|
|
||||||
@@ -6352,7 +6362,7 @@
|
|||||||
strictEqual(_.has(object, path), false);
|
strictEqual(_.has(object, path), false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}());
|
}(1, 2, 3));
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user