From e33b15674d873cac092c4be86fe4bd902efc455f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 30 Dec 2016 18:09:11 -0600 Subject: [PATCH] =?UTF-8?q?Ensure=20`=5F.omit`=20doesn=E2=80=99t=20mutate?= =?UTF-8?q?=20`object`=20with=20deep=20paths.=20[closes=20#2912]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lodash.js | 4 ++-- test/test.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index 8d93d7ea0..be3c7c669 100644 --- a/lodash.js +++ b/lodash.js @@ -5632,8 +5632,8 @@ * @param {string} key The key of the property to inspect. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`. */ - function customOmitClone(value, key) { - return (key !== undefined && isPlainObject(value)) ? undefined : value; + function customOmitClone(value) { + return isPlainObject(value) ? undefined : value; } /** diff --git a/test/test.js b/test/test.js index 9d34d4389..c75e2e923 100644 --- a/test/test.js +++ b/test/test.js @@ -16450,6 +16450,16 @@ assert.deepEqual(_.omit(object, args), { 'b': 2, 'd': 4 }); }); + + QUnit.test('should not mutate `object`', function(assert) { + assert.expect(4); + + lodashStable.each(['a', ['a'], 'a.b', ['a.b']], function(path) { + var object = { 'a': { 'b': 2 } }; + _.omit(object, path); + assert.deepEqual(object, { 'a': { 'b': 2 } }); + }); + }); }()); /*--------------------------------------------------------------------------*/