From 732088dd44e68e9500cf63db860c0851a7c7b9ec Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 30 Nov 2018 10:17:51 +0100 Subject: [PATCH] assert: fix loose deepEqual map comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Loose map comparison had an logic error. It will now be properly compared. PR-URL: https://github.com/nodejs/node/pull/24749 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso --- lib/internal/util/comparisons.js | 4 +--- test/parallel/test-assert-deep.js | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 205d84f4840886..0596bd8b2a8b57 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -401,9 +401,7 @@ function mapMightHaveLoosePrim(a, b, prim, item, memo) { !innerDeepEqual(item, curB, false, memo)) { return false; } - const curA = a.get(altValue); - return curA === undefined && a.has(altValue) || - innerDeepEqual(item, curA, false, memo); + return !a.has(altValue) && innerDeepEqual(item, curB, false, memo); } function setEquiv(a, b, strict, memo) { diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index 45f4353ce6c577..36758682941046 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -380,6 +380,14 @@ assertOnlyDeepEqual( new Map([[1, {}]]), new Map([[true, {}]]) ); +assertOnlyDeepEqual( + new Map([[undefined, true]]), + new Map([[null, true]]) +); +assertNotDeepOrStrict( + new Map([[undefined, true]]), + new Map([[true, true]]) +); // GH-6416. Make sure circular refs don't throw. {