Ensure _.pickBy doesn’t treat keys with dots as deep paths. [closes #2808]

This commit is contained in:
John-David Dalton
2016-11-14 00:47:47 -08:00
parent 13d315a93b
commit 102c5f00d7
2 changed files with 19 additions and 1 deletions

View File

@@ -13551,7 +13551,16 @@
* // => { 'a': 1, 'c': 3 } * // => { 'a': 1, 'c': 3 }
*/ */
function pickBy(object, predicate) { function pickBy(object, predicate) {
return object == null ? {} : basePickBy(object, getAllKeysIn(object), getIteratee(predicate)); if (object == null) {
return {};
}
var props = arrayMap(getAllKeysIn(object), function(prop) {
return [prop];
});
predicate = getIteratee(predicate);
return basePickBy(object, props, function(value, path) {
return predicate(value, path[0]);
});
} }
/** /**

View File

@@ -17640,6 +17640,15 @@
assert.deepEqual(actual, { 'a': 1, 'c': 3 }); assert.deepEqual(actual, { 'a': 1, 'c': 3 });
}); });
QUnit.test('should not treat keys with dots as deep paths', function(assert) {
assert.expect(1);
var object = { 'a.b.c': 1 },
actual = _.pickBy(object, stubTrue);
assert.deepEqual(actual, { 'a.b.c': 1 });
});
}()); }());
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/