Skip to content

Commit 493ead1

Browse files
BridgeARtargos
authored andcommittedMay 14, 2019
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: #27652 PR-URL: #27653 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
1 parent 9ed5882 commit 493ead1

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed
 

‎lib/internal/util/comparisons.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const {
3737
const {
3838
getOwnNonIndexProperties,
3939
propertyFilter: {
40-
ONLY_ENUMERABLE
40+
ONLY_ENUMERABLE,
41+
SKIP_SYMBOLS
4142
}
4243
} = internalBinding('util');
4344

@@ -163,8 +164,9 @@ function innerDeepEqual(val1, val2, strict, memos) {
163164
if (val1.length !== val2.length) {
164165
return false;
165166
}
166-
const keys1 = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE);
167-
const keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE);
167+
const filter = strict ? ONLY_ENUMERABLE : ONLY_ENUMERABLE | SKIP_SYMBOLS;
168+
const keys1 = getOwnNonIndexProperties(val1, filter);
169+
const keys2 = getOwnNonIndexProperties(val2, filter);
168170
if (keys1.length !== keys2.length) {
169171
return false;
170172
}
@@ -198,8 +200,9 @@ function innerDeepEqual(val1, val2, strict, memos) {
198200
// Buffer.compare returns true, so val1.length === val2.length. If they both
199201
// only contain numeric keys, we don't need to exam further than checking
200202
// the symbols.
201-
const keys1 = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE);
202-
const keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE);
203+
const filter = strict ? ONLY_ENUMERABLE : ONLY_ENUMERABLE | SKIP_SYMBOLS;
204+
const keys1 = getOwnNonIndexProperties(val1, filter);
205+
const keys2 = getOwnNonIndexProperties(val2, filter);
203206
if (keys1.length !== keys2.length) {
204207
return false;
205208
}

‎test/parallel/test-assert-deep.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ assertDeepAndStrictEqual(-0, -0);
639639
const b = new Uint8Array(4);
640640
a[symbol1] = true;
641641
b[symbol1] = false;
642-
assertNotDeepOrStrict(a, b);
642+
assertOnlyDeepEqual(a, b);
643643
b[symbol1] = true;
644644
assertDeepAndStrictEqual(a, b);
645645
// The same as TypedArrays is valid for boxed primitives
@@ -649,6 +649,13 @@ assertDeepAndStrictEqual(-0, -0);
649649
assertOnlyDeepEqual(boxedStringA, boxedStringB);
650650
boxedStringA[symbol1] = true;
651651
assertDeepAndStrictEqual(a, b);
652+
// Loose equal arrays should not compare symbols.
653+
const arr = [1];
654+
const arr2 = [1];
655+
arr[symbol1] = true;
656+
assertOnlyDeepEqual(arr, arr2);
657+
arr2[symbol1] = false;
658+
assertOnlyDeepEqual(arr, arr2);
652659
}
653660

654661
assert.throws(

0 commit comments

Comments
 (0)
Please sign in to comment.