Skip to content

Add node:util MIMEType.parse() - #8108

Merged
bartlomieju merged 1 commit into
cloudflare:mainfrom
JosephDoUrden:feat/mimetype-parse
Nov 28, 2026
Merged

bartlomieju merged 1 commit into
cloudflare:mainfrom
JosephDoUrden:feat/mimetype-parse

Conversation

@JosephDoUrden

Copy link
Copy Markdown
Contributor

Fixes #7663.

Adds the static MIMEType.parse(string) that Node.js 24.21 / 26.8 added to node:util: same parser as the constructor, null instead of a throw when the input is not a valid MIME type. The argument goes through ToString even when it is missing, so MIMEType.parse() returns null (the constructor throws for a missing argument), and a Symbol still throws, as in Node. The already-parsed record is adopted through the module-private token MIMEParams already uses, so nothing is parsed twice.

Tests: test_static_parse runs every case in parseCases through parse() and checks null exactly where the constructor throws and an equal MIMEType otherwise, plus the coercion cases, lone surrogates, that the result is live (params.set and setters write through), parse.length, and parse inside the patched-builtins test.

I could not run bazel locally for this one (disk), so the wd_test runs here on CI; the module and the test file pass under a Node harness that bundles internal_mime.ts directly.

@JosephDoUrden
JosephDoUrden requested review from a team as code owners October 30, 2026 20:40
@clanky-the-clanker

Copy link
Copy Markdown

This pull request was not reviewed automatically because its author does not have write access to this repository. A maintainer with write access can start a review by commenting clanky review (or clanker review or @clanky-the-clanker review), optionally followed by instructions (e.g. clanky review focus on the retry logic).

@JosephDoUrden

Copy link
Copy Markdown
Contributor Author

The two red bazel jobs are clang-tidy failures on C++ files this PR does not touch (same on #8116); the mimetype wd_test passed.

@jasnell

jasnell commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Can I ask you to rebase on latest main to see if that addresses the clang-tidy fails

@JosephDoUrden

Copy link
Copy Markdown
Contributor Author

Rebased on main.

@JosephDoUrden
JosephDoUrden force-pushed the feat/mimetype-parse branch 2 times, most recently from 49a1c4b to dc89d9a Compare November 5, 2026 12:51
@JosephDoUrden

JosephDoUrden commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

rebased onto today's main; the workflows are waiting for approval.

@JosephDoUrden

Copy link
Copy Markdown
Contributor Author

unrelated flakes, rerun please?

Node.js 24.21 added the static MIMEType.parse(string): it parses like
the constructor but returns null instead of throwing when the input is
not a valid MIME type. The argument goes through ToString even when it
is missing, so MIMEType.parse() with no argument returns null, while a
Symbol still throws. The parsed record is adopted directly rather than
parsed a second time.

Compatibility: this adds a static method to node:util's MIMEType at
every compatibility date, without a flag, which we accept. The only
observable change is that code feature-detecting MIMEType.parse now
takes the native branch.

Fixes cloudflare#7663
@JosephDoUrden

Copy link
Copy Markdown
Contributor Author

rebased onto main after #8868

@bartlomieju
bartlomieju merged commit 0ab08a3 into cloudflare:main Nov 28, 2026
71 of 79 checks passed
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.

Runtime APIs: support MIMEType.parse() from node:util

3 participants