Skip to content

Commit 493ead1

Browse files
BridgeARtargos
authored andcommitted
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 <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
1 parent 9ed5882 commit 493ead1

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎lib/internal/util/comparisons.js‎

Lines changed: 8 additions & 5 deletions
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
returnfalse;
165166
}
166-
constkeys1=getOwnNonIndexProperties(val1,ONLY_ENUMERABLE);
167-
constkeys2=getOwnNonIndexProperties(val2,ONLY_ENUMERABLE);
167+
constfilter=strict ? ONLY_ENUMERABLE : ONLY_ENUMERABLE|SKIP_SYMBOLS;
168+
constkeys1=getOwnNonIndexProperties(val1,filter);
169+
constkeys2=getOwnNonIndexProperties(val2,filter);
168170
if(keys1.length!==keys2.length){
169171
returnfalse;
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-
constkeys1=getOwnNonIndexProperties(val1,ONLY_ENUMERABLE);
202-
constkeys2=getOwnNonIndexProperties(val2,ONLY_ENUMERABLE);
203+
constfilter=strict ? ONLY_ENUMERABLE : ONLY_ENUMERABLE|SKIP_SYMBOLS;
204+
constkeys1=getOwnNonIndexProperties(val1,filter);
205+
constkeys2=getOwnNonIndexProperties(val2,filter);
203206
if(keys1.length!==keys2.length){
204207
returnfalse;
205208
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ assertDeepAndStrictEqual(-0, -0);
639639
constb=newUint8Array(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+
constarr=[1];
654+
constarr2=[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)