From 3f8dd7e658bf2b17bf7ca3b3c0f084ef9159f46e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 27 Dec 2014 23:09:56 -0600 Subject: [PATCH] Add test for `customizer` results of `NaN`. --- lodash.js | 8 +++++--- test/test.js | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lodash.js b/lodash.js index 3be6d1dcf..95d844a6c 100644 --- a/lodash.js +++ b/lodash.js @@ -1695,7 +1695,8 @@ var value = object[key], result = customizer(value, source[key], key, object, source); - if (result !== value || (typeof value == 'undefined' && !(key in object))) { + if ((result === result ? result !== value : value === value) || + (typeof value == 'undefined' && !(key in object))) { object[key] = result; } } else { @@ -2496,7 +2497,8 @@ if (isCommon) { result = srcValue; } - if ((isSrcArr || typeof result != 'undefined') && (isCommon || result !== value)) { + if ((isSrcArr || typeof result != 'undefined') && + (isCommon || (result === result ? result !== value : value === value))) { object[key] = result; } return; @@ -2528,7 +2530,7 @@ // Recursively merge objects and arrays (susceptible to call stack limits). if (isCommon) { object[key] = baseMerge(result, srcValue, customizer, stackA, stackB); - } else if (result !== value) { + } else if (result === result ? result !== value : value === value) { object[key] = result; } }); diff --git a/test/test.js b/test/test.js index 471113d53..317540080 100644 --- a/test/test.js +++ b/test/test.js @@ -4796,8 +4796,8 @@ deepEqual(actual, { 'a': 1, 'b': 2, 'c': 3 }); }); - test('`_.' + methodName + '` should not assign the `customizer` result if it is the same as the destination value', 3, function() { - _.each(['a', ['a'], { 'a': 1 }], function(value) { + test('`_.' + methodName + '` should not assign the `customizer` result if it is the same as the destination value', 4, function() { + _.each(['a', ['a'], { 'a': 1 }, NaN], function(value) { if (defineProperty) { var object = {}, pass = true;