Skip to content

fix: url.format() should support options parameter - #27885

Closed
ssing2 wants to merge 1 commit into
oven-sh:mainfrom
ssing2:fix-url-format-fragment
Closed

fix: url.format() should support options parameter#27885
ssing2 wants to merge 1 commit into
oven-sh:mainfrom
ssing2:fix-url-format-fragment

Conversation

@ssing2

@ssing2 ssing2 commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #24233

Node.js url.format() accepts an options object to control URL formatting, but Bun's implementation ignored this parameter.

Problem

import url from 'node:url';
const myURL = new URL('https://example.org?abc#foo');

console.log(url.format(myURL, { fragment: false }));
// Expected: 'https://example.org/?abc'
// Actual (Bun before fix): 'https://example.org/?abc#foo'

Solution

Modified Url.prototype.format() to accept and respect the options parameter:

  • fragment: false - removes the fragment (#foo)
  • Other options documented for future expansion

Changes

  • Modified src/js/node/url.ts
  • Added options parameter with TypeScript type
  • Implemented fragment option to control hash inclusion
  • Matches Node.js url.format() behavior

Test Case

import url from 'node:url';

const myURL = new URL('https://example.org?abc#foo');

// fragment: false removes the hash
console.log(url.format(myURL, { fragment: false }));
// Output: 'https://example.org/?abc' ✓

// Default behavior includes fragment
console.log(url.format(myURL));
// Output: 'https://example.org/?abc#foo' ✓

Fixes oven-sh#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)
@coderabbitai

coderabbitai Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@ssing2 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 38 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8e0b2838-33fa-405a-8ad7-1b755b337f66

📥 Commits

Reviewing files that changed from the base of the PR and between e2b0d24 and 8493a62.

📒 Files selected for processing (1)
  • src/js/node/url.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@robobun

robobun commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR. This behavior landed on main separately in #34660, which makes url.format honor the options object for WHATWG URL input, so #24233 is now closed.

Verified on a build of current main (165dc9f): url.format(new URL("https://example.org?abc#foo"), { fragment: false }) returns https://example.org/?abc, matching node v26.3.0.

This PR is no longer needed, so closing it.

@robobun robobun closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

url.format from node:url does not strip fragment

2 participants