mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Ensure _.has returns false for nested inherited properties. [closes #2073]
This commit is contained in:
14
lodash.js
14
lodash.js
@@ -5086,10 +5086,16 @@
|
|||||||
var result = hasFunc(object, path);
|
var result = hasFunc(object, path);
|
||||||
if (!result && !isKey(path)) {
|
if (!result && !isKey(path)) {
|
||||||
path = baseCastPath(path);
|
path = baseCastPath(path);
|
||||||
object = parent(object, path);
|
|
||||||
if (object != null) {
|
var index = -1,
|
||||||
path = last(path);
|
length = path.length;
|
||||||
result = hasFunc(object, path);
|
|
||||||
|
while (object != null && ++index < length) {
|
||||||
|
var key = path[index];
|
||||||
|
if (!(result = hasFunc(object, key))) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
object = object[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var length = object ? object.length : undefined;
|
var length = object ? object.length : undefined;
|
||||||
|
|||||||
11
test/test.js
11
test/test.js
@@ -7096,6 +7096,17 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('`_.' + methodName + '` should return `' + (isHas ? 'false' : 'true') + '` for nested inherited properties', function(assert) {
|
||||||
|
assert.expect(2);
|
||||||
|
|
||||||
|
function Foo() {}
|
||||||
|
Foo.prototype.a = { 'b': 1 };
|
||||||
|
|
||||||
|
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||||
|
assert.strictEqual(func(new Foo, path), !isHas);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
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(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user