8000 Ensure `_.pickBy` doesn’t treat keys with dots as deep paths. [closes… · lodash/lodash@102c5f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 102c5f0

Browse files
committed
Ensure _.pickBy doesn’t treat keys with dots as deep paths. [closes #2808]
1 parent 13d315a commit 102c5f0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lodash.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13551,7 +13551,16 @@
1355113551
* // => { 'a': 1, 'c': 3 }
1355213552
*/
1355313553
function pickBy(object, predicate) {
13554-
return object == null ? {} : basePickBy(object, getAllKeysIn(object), getIteratee(predicate));
13554+
if (object == null) {
13555+
return {};
13556+
}
13557+
var props = arrayMap(getAllKeysIn(object), function(prop) {
13558+
return [prop];
13559+
});
13560+
predicate = getIteratee(predicate);
13561+
return basePickBy(object, props, function(value, path) {
13562+
return predicate(value, path[0]);
13563+
});
1355513564
}
1355613565

1355713566
/**

test/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17640,6 +17640,15 @@
1764017640

1764117641
assert.deepEqual(actual, { 'a': 1, 'c': 3 });
1764217642
});
17643+
17644+
QUnit.test('should not treat keys with dots as deep paths', function(assert) {
17645+
assert.expect(1);
17646+
17647+
var object = { 'a.b.c': 1 },
17648+
actual = _.pickBy(object, stubTrue);
17649+
17650+
assert.deepEqual(actual, { 'a.b.c': 1 });
17651+
});
1764317652
}());
1764417653

1764517654
/*--------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)
0