assert: loose deep equal should not compare symbol properties
This is the way it's currently documented and that seems appropriate for loose equal assertions. The change was not intentional. Fixes: https://github.com/nodejs/node/issues/27652 PR-URL: https://github.com/nodejs/node/pull/27653 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
This commit is contained in:
parent
7294897c77
commit
3aff26428b
@ -37,7 +37,8 @@ const {
|
|||||||
const {
|
const {
|
||||||
getOwnNonIndexProperties,
|
getOwnNonIndexProperties,
|
||||||
propertyFilter: {
|
propertyFilter: {
|
||||||
ONLY_ENUMERABLE
|
ONLY_ENUMERABLE,
|
||||||
|
SKIP_SYMBOLS
|
||||||
}
|
}
|
||||||
} = internalBinding('util');
|
} = internalBinding('util');
|
||||||
|
|
||||||
@ -163,8 +164,9 @@ function innerDeepEqual(val1, val2, strict, memos) {
|
|||||||
if (val1.length !== val2.length) {
|
if (val1.length !== val2.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const keys1 = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE);
|
const filter = strict ? ONLY_ENUMERABLE : ONLY_ENUMERABLE | SKIP_SYMBOLS;
|
||||||
const keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE);
|
const keys1 = getOwnNonIndexProperties(val1, filter);
|
||||||
|
const keys2 = getOwnNonIndexProperties(val2, filter);
|
||||||
if (keys1.length !== keys2.length) {
|
if (keys1.length !== keys2.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -198,8 +200,9 @@ function innerDeepEqual(val1, val2, strict, memos) {
|
|||||||
// Buffer.compare returns true, so val1.length === val2.length. If they both
|
// Buffer.compare returns true, so val1.length === val2.length. If they both
|
||||||
// only contain numeric keys, we don't need to exam further than checking
|
// only contain numeric keys, we don't need to exam further than checking
|
||||||
// the symbols.
|
// the symbols.
|
||||||
const keys1 = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE);
|
const filter = strict ? ONLY_ENUMERABLE : ONLY_ENUMERABLE | SKIP_SYMBOLS;
|
||||||
const keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE);
|
const keys1 = getOwnNonIndexProperties(val1, filter);
|
||||||
|
const keys2 = getOwnNonIndexProperties(val2, filter);
|
||||||
if (keys1.length !== keys2.length) {
|
if (keys1.length !== keys2.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -639,7 +639,7 @@ assertDeepAndStrictEqual(-0, -0);
|
|||||||
const b = new Uint8Array(4);
|
const b = new Uint8Array(4);
|
||||||
a[symbol1] = true;
|
a[symbol1] = true;
|
||||||
b[symbol1] = false;
|
b[symbol1] = false;
|
||||||
assertNotDeepOrStrict(a, b);
|
assertOnlyDeepEqual(a, b);
|
||||||
b[symbol1] = true;
|
b[symbol1] = true;
|
||||||
assertDeepAndStrictEqual(a, b);
|
assertDeepAndStrictEqual(a, b);
|
||||||
// The same as TypedArrays is valid for boxed primitives
|
// The same as TypedArrays is valid for boxed primitives
|
||||||
@ -649,6 +649,13 @@ assertDeepAndStrictEqual(-0, -0);
|
|||||||
assertOnlyDeepEqual(boxedStringA, boxedStringB);
|
assertOnlyDeepEqual(boxedStringA, boxedStringB);
|
||||||
boxedStringA[symbol1] = true;
|
boxedStringA[symbol1] = true;
|
||||||
assertDeepAndStrictEqual(a, b);
|
assertDeepAndStrictEqual(a, b);
|
||||||
|
// Loose equal arrays should not compare symbols.
|
||||||
|
const arr = [1];
|
||||||
|
const arr2 = [1];
|
||||||
|
arr[symbol1] = true;
|
||||||
|
assertOnlyDeepEqual(arr, arr2);
|
||||||
|
arr2[symbol1] = false;
|
||||||
|
assertOnlyDeepEqual(arr, arr2);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user