Skip to content

Commit e5558b0

Browse files
BridgeARaduh95
authored andcommitted
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: #61076 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 8b6be3f commit e5558b0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/internal/util/comparisons.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ function objectComparisonStart(val1, val2, mode, memos) {
302302
DatePrototypeGetTime(val1) !== DatePrototypeGetTime(val2)) {
303303
return false;
304304
}
305+
const time1 = DatePrototypeGetTime(val1);
306+
const time2 = DatePrototypeGetTime(val2);
307+
// eslint-disable-next-line no-self-compare
308+
if (time1 !== time2 && (time1 === time1 || time2 === time2)) {
309+
return false;
310+
}
305311
} else if (isRegExp(val1)) {
306312
if (!isRegExp(val2) || !areSimilarRegExps(val1, val2)) {
307313
return false;

test/parallel/test-assert-deep.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,19 @@ test('Additional tests', () => {
779779

780780
assertNotDeepOrStrict(new Date(), new Date(2000, 3, 14));
781781

782+
{
783+
// Invalid dates deep comparison.
784+
const date1 = new Date('foo');
785+
const date2 = new Date('bar');
786+
date1.foo = true;
787+
date2.foo = true;
788+
assertDeepAndStrictEqual(date1, date2);
789+
790+
date1.bar = false;
791+
date2.bar = true;
792+
assertNotDeepOrStrict(date1, date2);
793+
}
794+
782795
assertDeepAndStrictEqual(/a/, /a/);
783796
assertDeepAndStrictEqual(/a/g, /a/g);
784797
assertDeepAndStrictEqual(/a/i, /a/i);

0 commit comments

Comments
 (0)