Skip to content

Commit fc1d6d6

Browse files
BridgeARnodejs-github-bot
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 <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent a968e4e commit fc1d6d6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/internal/util/comparisons.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ function objectComparisonStart(val1, val2, mode, memos) {
304304
}
305305
const time1 = DatePrototypeGetTime(val1);
306306
const time2 = DatePrototypeGetTime(val2);
307-
if (time1 !== time2) {
308-
// eslint-disable-next-line no-self-compare
309-
return time1 !== time1 && time2 !== time2;
307+
// eslint-disable-next-line no-self-compare
308+
if (time1 !== time2 && (time1 === time1 || time2 === time2)) {
309+
return false;
310310
}
311311
} else if (isRegExp(val1)) {
312312
if (!isRegExp(val2) || !areSimilarRegExps(val1, val2)) {

test/parallel/test-assert-deep.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,18 @@ test('Additional tests', () => {
752752

753753
assertNotDeepOrStrict(new Date(), new Date(2000, 3, 14));
754754

755-
assertDeepAndStrictEqual(new Date('foo'), new Date('bar'));
755+
{
756+
// Invalid dates deep comparison.
757+
const date1 = new Date('foo');
758+
const date2 = new Date('bar');
759+
date1.foo = true;
760+
date2.foo = true;
761+
assertDeepAndStrictEqual(date1, date2);
762+
763+
date1.bar = false;
764+
date2.bar = true;
765+
assertNotDeepOrStrict(date1, date2);
766+
}
756767

757768
assertDeepAndStrictEqual(/a/, /a/);
758769
assertDeepAndStrictEqual(/a/g, /a/g);

0 commit comments

Comments
 (0)