Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e5558b0

Browse filesBrowse 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
Copy full SHA for e5558b0

2 files changed

+19Lines changed: 19 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/util/comparisons.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/comparisons.js
+6Lines 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;
Collapse file

‎test/parallel/test-assert-deep.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js
+13Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.