★ wanayoo — archive 1999 https://github.com/nodejs/node/commit/8905518650Nouvelle recherche | Portail wanayoo
Skip to content
Permalink
Browse files

assert,util: fix sparse array comparison

Comparing sparse arrays did not work properly. That is fixed and
tests were added to verify that everything works as expected.

This had an impact on `util.isDeepStrictEqual()` and
`assert.deepStrictEqual()` and their counterpart
`assert.notDeepStrictEqual()`.

PR-URL: #24749
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information...
BridgeAR committed Nov 30, 2018
1 parent 7fb8d31 commit 890551865009a4f87b0f3b8a57ad749b8af64306
Showing with 15 additions and 5 deletions.
  1. +1 −2 lib/internal/util/comparisons.js
  2. +14 −3 test/parallel/test-assert-deep.js
@@ -558,11 +558,10 @@ function objEquiv(a, b, strict, keys, memos, iterationType) {
} else {
// Array is sparse.
const keysA = objectKeys(a);
i++;
for (; i < keysA.length; i++) {
const key = keysA[i];
if (!hasOwnProperty(b, key) ||
!innerDeepEqual(a[key], b[i], strict, memos)) {
!innerDeepEqual(a[key], b[key], strict, memos)) {
return false;
}
}
@@ -571,9 +571,20 @@ assertNotDeepOrStrict(
assertDeepAndStrictEqual(m3, m4);
}

// Handle sparse arrays
assertDeepAndStrictEqual([1, , , 3], [1, , , 3]);
assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]);
// Handle sparse arrays.
{
assertDeepAndStrictEqual([1, , , 3], [1, , , 3]);
assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]);
const a = new Array(3);
const b = new Array(3);
a[2] = true;
b[1] = true;
assertNotDeepOrStrict(a, b);
b[2] = true;
assertNotDeepOrStrict(a, b);
a[0] = true;
assertNotDeepOrStrict(a, b);
}

// Handle different error messages
{

0 comments on commit 8905518

Please sign in to comment.
You can’t perform that action at this time.