From d82593741118a0b61021514cc803a70c94400107 Mon Sep 17 00:00:00 2001 From: jdalton Date: Sun, 3 May 2015 22:57:45 -0700 Subject: [PATCH] Ensure `customizer` results are respected by `_.isEqual`. --- lodash.src.js | 5 ++++- test/test.js | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index ed496ecb6..b42720f84 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -3928,7 +3928,10 @@ othValue = other[index], result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined; - if (result !== undefined && !result) { + if (result !== undefined) { + if (result) { + continue; + } return false; } // Recursively compare arrays (susceptible to call stack limits). diff --git a/test/test.js b/test/test.js index d96262d78..24804e787 100644 --- a/test/test.js +++ b/test/test.js @@ -7749,15 +7749,26 @@ strictEqual(_.isEqual('a', 'a', _.noop), true); }); + test('should not handle comparisons if `customizer` returns `true`', 3, function() { + var customizer = function(value) { + return _.isString(value) || undefined; + }; + + strictEqual(_.isEqual('a', 'b', customizer), true); + strictEqual(_.isEqual(['a'], ['b'], customizer), true); + strictEqual(_.isEqual({ '0': 'a' }, { '0': 'b' }, customizer), true); + }); + test('should return a boolean value even if `customizer` does not', 2, function() { - var actual = _.isEqual('a', 'a', _.constant('a')); + var actual = _.isEqual('a', 'b', _.constant('c')); strictEqual(actual, true); - var expected = _.map(falsey, _.constant(false)); + var values = _.without(falsey, undefined), + expected = _.map(values, _.constant(false)); actual = []; - _.each(falsey, function(value) { - actual.push(_.isEqual('a', 'b', _.constant(value))); + _.each(values, function(value) { + actual.push(_.isEqual('a', 'a', _.constant(value))); }); deepEqual(actual, expected);