Skip to content

Commit 42fa62c

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 <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 266279a commit 42fa62c

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
@@ -978,9 +978,10 @@ function objEquiv(a, b, mode, keys1, keys2, memos, iterationType) {
978978
if (b[i] === undefined) {
979979
if (!hasOwn(b, i))
980980
return sparseArrayEquiv(a, b, mode, memos, i);
981-
if (a[i] !== undefined || !hasOwn(a, i))
981+
if ((a[i] !== undefined || !hasOwn(a, i)) && (mode !== kLoose || a[i] !== null))
982982
return false;
983-
} else if (a[i] === undefined || !innerDeepEqual(a[i], b[i], mode, memos)) {
983+
} else if ((a[i] === undefined || !innerDeepEqual(a[i], b[i], mode, memos)) &&
984+
(mode !== kLoose || b[i] !== null)) {
984985
return false;
985986
}
986987
}

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)