From fc1d6d6b4c6f9c41817de09e7a37543d8067fc57 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 15 Dec 2025 17:56:36 +0100 Subject: [PATCH] assert,util: fix deep comparing invalid dates skipping properties The property comparison of invalid dates regressed when starting to handle invalid dates as being equal. PR-URL: https://github.com/nodejs/node/pull/61076 Reviewed-By: Colin Ihrig Reviewed-By: Yagiz Nizipli Reviewed-By: Antoine du Hamel --- lib/internal/util/comparisons.js | 6 +++--- test/parallel/test-assert-deep.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index b58b828a96..3b800b48b7 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -304,9 +304,9 @@ function objectComparisonStart(val1, val2, mode, memos) { } const time1 = DatePrototypeGetTime(val1); const time2 = DatePrototypeGetTime(val2); - if (time1 !== time2) { - // eslint-disable-next-line no-self-compare - return time1 !== time1 && time2 !== time2; + // eslint-disable-next-line no-self-compare + if (time1 !== time2 && (time1 === time1 || time2 === time2)) { + return false; } } else if (isRegExp(val1)) { if (!isRegExp(val2) || !areSimilarRegExps(val1, val2)) { diff --git a/test/parallel/test-assert-deep.js b/test/parallel/test-assert-deep.js index 73da19017a..9c1d8eefe0 100644 --- a/test/parallel/test-assert-deep.js +++ b/test/parallel/test-assert-deep.js @@ -752,7 +752,18 @@ test('Additional tests', () => { assertNotDeepOrStrict(new Date(), new Date(2000, 3, 14)); - assertDeepAndStrictEqual(new Date('foo'), new Date('bar')); + { + // Invalid dates deep comparison. + const date1 = new Date('foo'); + const date2 = new Date('bar'); + date1.foo = true; + date2.foo = true; + assertDeepAndStrictEqual(date1, date2); + + date1.bar = false; + date2.bar = true; + assertNotDeepOrStrict(date1, date2); + } assertDeepAndStrictEqual(/a/, /a/); assertDeepAndStrictEqual(/a/g, /a/g);