Skip to content

Commit 3d8064f

Browse files
committed
assert: fix loose deepEqual arrays with undefined and null failing
The comparison has to accept these as identical. Fixes: #61583
1 parent 784ca7b commit 3d8064f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/internal/util/comparisons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,9 @@ function objEquiv(a, b, mode, keys1, keys2, memos, iterationType) {
999999
if (!hasOwn(b, i))
10001000
return sparseArrayEquiv(a, b, mode, memos, i);
10011001
if (a[i] !== undefined || !hasOwn(a, i))
1002-
return false;
1002+
return mode !== kLoose ? false : a[i] === null;
10031003
} else if (a[i] === undefined || !innerDeepEqual(a[i], b[i], mode, memos)) {
1004-
return false;
1004+
return mode !== kLoose ? false : b[i] === null;
10051005
}
10061006
}
10071007
} else if (iterationType === kIsSet) {

test/parallel/test-assert-deep.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ test('deepEqual', () => {
126126
}
127127
});
128128

129+
test('loose deepEqual', () => {
130+
assertOnlyDeepEqual([null, undefined, undefined], [null, undefined, null])
131+
});
132+
129133
test('date', () => {
130134
assertNotDeepOrStrict(date, date2);
131135
assert.throws(
@@ -246,6 +250,13 @@ function assertOnlyDeepEqual(a, b, err) {
246250
() => assert.deepStrictEqual(b, a),
247251
err || { code: 'ERR_ASSERTION' }
248252
);
253+
254+
const partial = mustCall(() => {
255+
assert.partialDeepStrictEqual(b, a);
256+
assert.partialDeepStrictEqual(a, b);
257+
});
258+
259+
assert.throws(partial, err || { code: 'ERR_ASSERTION' });
249260
}
250261

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

0 commit comments

Comments
 (0)