Skip to content

fix(url): handle :port values in host setter #963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

watilde
Copy link
Contributor

@watilde watilde commented Jun 28, 2025

The current implementation incorrectly allows values like ":80" (empty host with port), resulting in foo://:80/to, while the spec requires failure if the host is missing. This update aligns behavior with the spec.

const NodeURL = require("url").URL;
const WhatwgURL = require("whatwg-url").URL;
const newHost = ':80';

const url = new NodeURL("foo://path/to");  
url.host = newHost;
console.log(url.href); // Wrong: foo://:80/to

const url2 = new WhatwgURL("foo://path/to");
url2.host = newHost;
console.log(url2.href); // Correct: foo://path/to

Refs: https://url.spec.whatwg.org/#host-state

If buffer is the empty string, host-missing validation error, return failure.

WPT tests for this case will be added in a follow-up PR.

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.

1 participant