Skip to content

Commit 41b5172

Browse files
BridgeARrvagg
authored andcommitted
util,assert: fix boxed primitives bug
Currently the comparison could throw an error in case a boxed primitive has no valueOf function on one side of the assert call. PR-URL: #22243 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: George Adams <[email protected]>
1 parent 7cb05cf commit 41b5172

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

‎lib/internal/util/comparisons.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ function strictDeepEqual(val1, val2, memos){
120120
constval1Value=val1.valueOf();
121121
// Note: Boxed string keys are going to be compared again by Object.keys
122122
if(val1Value!==val1){
123+
if(typeofval2.valueOf!=='function'){
124+
returnfalse;
125+
}
123126
if(!innerDeepEqual(val1Value,val2.valueOf(),true))
124127
returnfalse;
125128
// Fast path for boxed primitives

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,3 +931,10 @@ assert.throws(() => assert.deepStrictEqual(new Boolean(true),{}),
931931
);
932932
util.inspect.defaultOptions=tmp;
933933
}
934+
935+
// Basic valueOf check.
936+
{
937+
consta=newString(1);
938+
a.valueOf=undefined;
939+
assertNotDeepOrStrict(a,newString(1));
940+
}

0 commit comments

Comments
(0)