Skip to content

Commit 9c8d1b0

Browse 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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Jordan Harband <[email protected]> Reviewed-By: Ulises Gascón <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent 45d25c4 commit 9c8d1b0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/internal/util/comparisons.js

Lines 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
}

test/parallel/test-assert-deep.js

Lines 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)