Skip to content

URL: add port setter tests with newlines and tabs#53420

Merged
anonrig merged 1 commit intoweb-platform-tests:masterfrom
watilde:test/url-setters-newline-tab
Jun 26, 2025
Merged

URL: add port setter tests with newlines and tabs#53420
anonrig merged 1 commit intoweb-platform-tests:masterfrom
watilde:test/url-setters-newline-tab

Conversation

@watilde
Copy link
Contributor

@watilde watilde commented Jun 26, 2025

While comparing the behavior of the URL port setter between Node.js and whatwg-url, I found a difference in how inputs containing only newlines and tabs are handled.

For example, running the following code:

const NodeURL = require("url").URL;
const WhatwgURL = require("whatwg-url").URL;

const url = new NodeURL("https://example.com:3000");
url.port = "\n\n\t\t";
console.log(url.port); // "" (the port is cleared in Node.js)

const url2 = new WhatwgURL("https://example.com:3000");
url2.port = "\n\n\t\t";
console.log(url2.port); // "3000" (the port remains unchanged in whatwg-url)

According to the WHATWG URL Standard, the port should remain unchanged when the input consists only of ASCII tab, newline, or carriage return characters. To ensure this behavior, I am adding new Web Platform Tests (WPT) for the port setter with such inputs.

@lemire
Copy link
Member

lemire commented Jun 26, 2025

Here is the current behaviour in all three main JavaScript runtimes:

Bun:

Capture d’écran, le 2025-06-26 à 12 01 51

Deno:

Capture d’écran, le 2025-06-26 à 12 03 34

Node

Capture d’écran, le 2025-06-26 à 12 04 24

@lemire
Copy link
Member

lemire commented Jun 26, 2025

I expect that @watilde is correct. Anything non-empty that does not parse to a 16-bit integer should leave the port unchanged.

But it is evidently a widespread non-compliance with the specification.

@anonrig anonrig merged commit 45531ab into web-platform-tests:master Jun 26, 2025
25 checks passed
@watilde watilde deleted the test/url-setters-newline-tab branch June 27, 2025 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants