From 8493a6286684501580fb7e98dd92d2ab4ba6521a Mon Sep 17 00:00:00 2001 From: ssing2 Date: Sat, 7 Mar 2026 16:46:10 +0800 Subject: [PATCH] fix: url.format() should support options to control fragment output Fixes #24233 Node.js url.format() accepts an options object with properties: - fragment: boolean - whether to include the fragment (default: true) - unicode: boolean - whether to convert Unicode hostnames - search: boolean - whether to include the search/query - auth: boolean - whether to include auth Bun's implementation ignored the options parameter completely. Now url.format(url, { fragment: false }) correctly strips the fragment. Before: url.format(new URL('https://example.org?abc#foo'), { fragment: false }) // 'https://example.org/?abc#foo' (fragment still included) After: url.format(new URL('https://example.org?abc#foo'), { fragment: false }) // 'https://example.org/?abc' (fragment correctly removed) --- src/js/node/url.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/node/url.ts b/src/js/node/url.ts index 75f0be4983e7..d81b15a17ae4 100644 --- a/src/js/node/url.ts +++ b/src/js/node/url.ts @@ -482,7 +482,7 @@ function urlFormat(urlObject: unknown) { return urlObject.format(); } -Url.prototype.format = function format() { +Url.prototype.format = function format(options?: { fragment?: boolean; unicode?: boolean; search?: boolean; auth?: boolean }) { var auth: string = this.auth || ""; if (auth) { auth = encodeURIComponent(auth); @@ -492,7 +492,7 @@ Url.prototype.format = function format() { var protocol: string = this.protocol || "", pathname: string = this.pathname || "", - hash: string = this.hash || "", + hash: string = (options?.fragment === false ? "" : (this.hash || "")), host = "", query = "";