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

Commit 6f580d5

Browse files
meixgmarco-ippolito
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 0561c62 commit 6f580d5

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
@@ -170,6 +170,11 @@ function pathToFileUrlHref(filepath) {
170170
return internalUrl.pathToFileURL(filepath).href;
171171
}
172172

173+
function isURL(value) {
174+
internalUrl ??= require('internal/url');
175+
return typeof value.href === 'string' && value instanceof internalUrl.URL;
176+
}
177+
173178
const builtInObjects = new SafeSet(
174179
ArrayPrototypeFilter(
175180
ObjectGetOwnPropertyNames(globalThis),
@@ -1045,6 +1050,11 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
10451050
if (keys.length === 0 && protoProps === undefined) {
10461051
return base;
10471052
}
1053+
} else if (isURL(value) && !(recurseTimes > ctx.depth && ctx.depth !== null)) {
1054+
base = value.href;
1055+
if (keys.length === 0 && protoProps === undefined) {
1056+
return base;
1057+
}
10481058
} else {
10491059
if (keys.length === 0 && protoProps === undefined) {
10501060
if (isExternal(value)) {

test/parallel/test-assert-deep.js

Lines changed: 44 additions & 0 deletions

0 commit comments

Comments
 (0)