mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Ensure _.get can return null values. [closes #1216]
This commit is contained in:
@@ -2259,11 +2259,11 @@
|
|||||||
if (pathKey !== undefined && pathKey in object) {
|
if (pathKey !== undefined && pathKey in object) {
|
||||||
path = [pathKey];
|
path = [pathKey];
|
||||||
}
|
}
|
||||||
var index = -1,
|
var index = 0,
|
||||||
length = path.length;
|
length = path.length;
|
||||||
|
|
||||||
while (object != null && ++index < length) {
|
while (object != null && index < length) {
|
||||||
object = toObject(object)[path[index]];
|
object = toObject(object)[path[index++]];
|
||||||
}
|
}
|
||||||
return (index && index == length) ? object : undefined;
|
return (index && index == length) ? object : undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13660,6 +13660,14 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('`_.' + methodName + '` should be able to return `null` values', 2, function() {
|
||||||
|
var object = { 'a': { 'b': null } };
|
||||||
|
|
||||||
|
_.each(['a.b', ['a', 'b']], function(path) {
|
||||||
|
strictEqual(func(object, path), null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should follow `path` over non-plain objects', 4, function() {
|
test('`_.' + methodName + '` should follow `path` over non-plain objects', 4, function() {
|
||||||
var object = { 'a': '' },
|
var object = { 'a': '' },
|
||||||
paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
|
paths = ['constructor.prototype.a', ['constructor', 'prototype', 'a']];
|
||||||
|
|||||||
Reference in New Issue
Block a user