From 7fb8d319fa52b50ea23855056f084c0284ee14e6 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 9adffea09a14c5..43a8921f657130 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -416,9 +416,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 a4533977608c00..db93f3b6e717bb 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -394,6 +394,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. {