From 9fb10dc4e752503002e9bf938c49783bd732ba50 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 11 Mar 2021 11:40:41 +0100 Subject: [PATCH] assert,util: fix commutativity edge case Verify that both objects property keys are enumerable. Fixes: https://github.com/nodejs/node/issues/37710 PR-URL: https://github.com/nodejs/node/pull/37711 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca Reviewed-By: Antoine du Hamel Reviewed-By: Rich Trott --- lib/internal/util/comparisons.js | 2 +- test/parallel/test-assert-deep.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index 2c10f0c8929752..8d5692777c94e2 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -315,7 +315,7 @@ function keyCheck(val1, val2, strict, memos, iterationType, aKeys) { // Cheap key test let i = 0; for (; i < aKeys.length; i++) { - if (!ObjectPrototypeHasOwnProperty(val2, aKeys[i])) { + if (!ObjectPrototypePropertyIsEnumerable(val2, aKeys[i])) { return false; } } diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index 73af4b3e226929..b14179c85c8a8f 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -1194,3 +1194,13 @@ assert.throws( Object.setPrototypeOf(b, null); assertNotDeepOrStrict(a, b, assert.AssertionError); } + +{ + // Verify commutativity + // Regression test for https://github.com/nodejs/node/issues/37710 + const a = { x: 1 }; + const b = { y: 1 }; + Object.defineProperty(b, 'x', { value: 1 }); + + assertNotDeepOrStrict(a, b); +}