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 9c8d1b0

Browse filesBrowse files
BridgeARaduh95
authored andcommitted
assert: fix loose deepEqual arrays with undefined and null failing
The comparison has to accept these as identical. Fixes: #61583 PR-URL: #61587 Reviewed-By: Jithil P Ponnan <jithil@outlook.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 45d25c4 commit 9c8d1b0
Copy full SHA for 9c8d1b0

2 files changed

+15-2Lines changed: 15 additions & 2 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
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,9 +998,10 @@ function objEquiv(a, b, mode, keys1, keys2, memos, iterationType) {
998998
if (b[i] === undefined) {
999999
if (!hasOwn(b, i))
10001000
return sparseArrayEquiv(a, b, mode, memos, i);
1001-
if (a[i] !== undefined || !hasOwn(a, i))
1001+
if ((a[i] !== undefined || !hasOwn(a, i)) && (mode !== kLoose || a[i] !== null))
10021002
return false;
1003-
} else if (a[i] === undefined || !innerDeepEqual(a[i], b[i], mode, memos)) {
1003+
} else if ((a[i] === undefined || !innerDeepEqual(a[i], b[i], mode, memos)) &&
1004+
(mode !== kLoose || b[i] !== null)) {
10041005
return false;
10051006
}
10061007
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-assert-deep.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ test('deepEqual', () => {
126126
}
127127
});
128128

129+
test('loose deepEqual', () => {
130+
assertOnlyDeepEqual([null, undefined, undefined], [null, undefined, null]);
131+
assertNotDeepOrStrict([null, undefined, undefined, 1], [null, undefined, null, 2]);
132+
});
133+
129134
test('date', () => {
130135
assertNotDeepOrStrict(date, date2);
131136
assert.throws(
@@ -246,6 +251,13 @@ function assertOnlyDeepEqual(a, b, err) {
246251
() => assert.deepStrictEqual(b, a),
247252
err || { code: 'ERR_ASSERTION' }
248253
);
254+
255+
const partial = mustCall(() => {
256+
assert.partialDeepStrictEqual(b, a);
257+
assert.partialDeepStrictEqual(a, b);
258+
});
259+
260+
assert.throws(partial, err || { code: 'ERR_ASSERTION' });
249261
}
250262

251263
test('es6 Maps and Sets', () => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.