assert: fix deepEqual always return true on URL · nodejs/node@907484f · GitHub
Skip to content

Commit 907484f

Browse files
meixgruyadorno
authored andcommitted
assert: fix deepEqual always return true on URL
PR-URL: #50853 Fixes: #50836 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 03902eb commit 907484f

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

lib/internal/util/comparisons.js

Lines changed: 5 additions & 0 deletions

lib/internal/util/inspect.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ function pathToFileUrlHref(filepath) {
166166
return internalUrl.pathToFileURL(filepath).href;
167167
}
168168

169+
function isURL(value) {
170+
internalUrl ??= require('internal/url');
171+
return typeof value.href === 'string' && value instanceof internalUrl.URL;
172+
}
173+
169174
const builtInObjects = new SafeSet(
170175
ArrayPrototypeFilter(
171176
ObjectGetOwnPropertyNames(globalThis),
@@ -1026,6 +1031,11 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
10261031
if (keys.length === 0 && protoProps === undefined) {
10271032
return base;
10281033
}
1034+
} else if (isURL(value) && !(recurseTimes > ctx.depth && ctx.depth !== null)) {
1035+
base = value.href;
1036+
if (keys.length === 0 && protoProps === undefined) {
1037+
return base;
1038+
}
10291039
} else {
10301040
if (keys.length === 0 && protoProps === undefined) {
10311041
if (isExternal(value)) {

test/parallel/test-assert-deep.js

Lines changed: 44 additions & 0 deletions

0 commit comments

Comments
 (0)