From 102c5f00d76096059cb6e1a8f9cf082dc6488334 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 14 Nov 2016 00:47:47 -0800 Subject: [PATCH] =?UTF-8?q?Ensure=20`=5F.pickBy`=20doesn=E2=80=99t=20treat?= =?UTF-8?q?=20keys=20with=20dots=20as=20deep=20paths.=20[closes=20#2808]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lodash.js | 11 ++++++++++- test/test.js | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index 5db9358e7..8b27a0483 100644 --- a/lodash.js +++ b/lodash.js @@ -13551,7 +13551,16 @@ * // => { 'a': 1, 'c': 3 } */ 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]); + }); } /** diff --git a/test/test.js b/test/test.js index c62c4e84c..50a0a6b93 100644 --- a/test/test.js +++ b/test/test.js @@ -17640,6 +17640,15 @@ 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 }); + }); }()); /*--------------------------------------------------------------------------*/