Skip to content

url: add experimental URLPatternList - #67807

Open
anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/util-urlpatternlist-30ce
Open

anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/util-urlpatternlist-30ce

Conversation

@anonrig

@anonrig anonrig commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Credit to @FranciscoThiesen, who wrote the C++ implementation and contributed it to Ada.

This adds url.URLPatternList, an experimental implementation of the
URLPatternList interface proposed in whatwg/urlpattern#166,
built on the ada::url_pattern_list API from the Ada 4.1.1 update.

const { URLPatternList } = require('node:url');

const patterns = [
  new URLPattern('https://example.com/about'),
  new URLPattern('https://example.com/blog/:slug'),
];
const list = new URLPatternList(patterns);
list.exec('https://example.com/blog/hello').pattern === patterns[1]; // true
list.test('https://example.com/contact'); // false

Behavior

This follows the spec PR:

  • new URLPatternList(patterns) takes an iterable of URLPattern objects. It
    throws a TypeError if a value is not a URLPattern, if the same
    URLPattern appears more than once, or if the list is empty. Strings,
    URLPatternInit dictionaries and options are not accepted, because the IDL
    is constructor(sequence<URLPattern> patterns). Each pattern keeps its own
    ignoreCase.
  • exec(input = {}, baseURL) returns the URLPattern#exec() result of the
    first pattern in list order that matches, plus a pattern member, or null.
  • test(input = {}, baseURL) returns whether any pattern matches.
  • The first construction emits an ExperimentalWarning. Loading or importing
    node:url does not.

Implementation

ada::url_pattern_list matches pathnames only and reports the most specific
route. The spec matches every component and returns the first match in list
order. So the list does not return Ada's route. It uses the index only to skip
work:

  • The input is processed once per call, as ada::url_pattern::match() does,
    and the patterns are matched with ada::url_pattern::test_components().
  • If no indexed pathname matches, no indexed pattern can match, so only the
    patterns outside the index are tested.
  • If the pattern behind the reported pathname matches, only the patterns before
    it need to be tested, and test() returns true right away.
  • A pattern is indexed only if its pathname was compiled the way the index
    compiles pathnames. Patterns with a non-special scheme, or with a different
    ignoreCase than the first indexed pattern, are always tested.

Like URLPattern, the class is implemented entirely in the url_pattern
binding, including the sequence<URLPattern> conversion, and node:url
exports the native class (it is not exposed on globalThis). The URLPattern
constructor template is now cached in IsolateData, as SocketAddress does,
so that the list can check that its values are URLPattern objects.

benchmark/url/urlpatternlist-exec.js compares the list with the
URLPattern#exec() loop that the spec describes. With 1000 routes:

Input URLPatternList URLPattern loop
First route 40,518 ops/s 40,232 ops/s
Last route 1,977 ops/s 659 ops/s
No match 515,417 ops/s 720 ops/s

Because the spec uses list order, a match late in the list still needs a linear
scan. Whether the order should stay as it is or become a specificity order
(what Ada's list implements) is still open in the spec PR.

Tests

  • test-urlpatternlist.js: interface shape, constructor conversion and
    errors, list order, matching on every component, inputs and base URLs, mixed
    ignoreCase, non-special schemes, regexp groups, non-ASCII input, large lists
    and long inputs, brand checks, and a seeded comparison with the spec's loop.
  • test-urlpatternlist-wpt.js: every URLPattern WPT case, as a list of one
    pattern and inside a list of all the WPT patterns, compared with the spec's
    loop.
  • test-urlpatternlist-experimental-warning.js and
    test-urlpatternlist-worker.js.

AI assistance

This change was written with the help of Cursor (Claude Opus 5.5). It was
verified locally on this branch with:

  • make -j38 test: tooltest, cctest (317 tests) and 7,623 JS tests pass. The
    68 other JS tests fail only because the build machine sets HTTP_PROXY,
    HTTPS_PROXY, NODE_DISABLE_COMPILE_CACHE, FORCE_COLOR and NO_COLOR,
    and they pass with those variables unset.
  • make lint, make doc-only, and git-clang-format against main.
  • Breaking the matching code on purpose in three places (ignoring list order,
    indexing patterns with non-special schemes, and skipping the patterns that
    the index does not cover) makes the new tests fail.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance
  • @nodejs/url

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. typings Issues and PRs related to internal TypeScript declarations. util Issues and PRs related to the built-in util module. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Nov 27, 2026
@anonrig anonrig added notable-change PRs with changes that should be highlighted in changelogs. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Nov 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The notable-change PRs with changes that should be highlighted in changelogs. label has been added by @anonrig.

Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section.

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.58025% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.51%. Comparing base (2dd55c3) to head (90a6fc9).
⚠️ Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
src/node_url_pattern.cc 88.92% 17 Missing and 18 partials ⚠️
src/node_url_pattern.h 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67807      +/-   ##
==========================================
+ Coverage   90.50%   90.51%   +0.01%     
==========================================
  Files         805      805              
  Lines      285818   286190     +372     
  Branches    55182    55269      +87     
==========================================
+ Hits       258666   259035     +369     
+ Misses      17251    17229      -22     
- Partials     9901     9926      +25     
Files with missing lines Coverage Δ
lib/url.js 100.00% <100.00%> (ø)
src/env.h 98.82% <100.00%> (+0.05%) ⬆️
src/node_url_pattern.h 0.00% <0.00%> (ø)
src/node_url_pattern.cc 85.63% <88.92%> (+2.42%) ⬆️

... and 56 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

cursor Bot pushed a commit to anonrig/node that referenced this pull request Nov 27, 2026
Shared-library CI builds Node against nixpkgs ada 4.0.0, which does
not provide ada::url_pattern_list. The vendored copy is ada 4.1.1, so
override the shared ada package to that release until the nixpkgs pin
includes it.

Refs: nodejs#67807
Assisted-by: Cursor Grok 4.7
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor
Platform Number of requisites Proportion of new derivations
x86_64-linux 518 -> 519 => +1 2 / 519 = 0.3%
aarch64-linux 519 -> 520 => +1 2 / 520 = 0.3%
x86_64-darwin 446 -> 447 => +1 1 / 447 = 0.2%
aarch64-darwin 448 -> 449 => +1 2 / 449 = 0.4%
Total 1931 -> 1935 => +4 7 / 1935 = 0.3%
Version changes
Package Version Platforms
ada added: 4.1.1 aarch64-darwin, aarch64-linux, x86_64-darwin, x86_64-linux
ada.dev 4.0.0 -> 4.1.1 aarch64-darwin, aarch64-linux, x86_64-linux

Comment thread doc/api/util.md Resolved
Comment thread doc/api/util.md Resolved
cursor Bot pushed a commit to anonrig/node that referenced this pull request Nov 27, 2026
Mark util.URLPatternList as stability 1.0 (early development) and note
that it is not a standard API, and that it is not yet clear whether it
will become one.

Refs: nodejs#67807
Assisted-by: Cursor Grok 4.7
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@anonrig
anonrig requested a review from jasnell November 27, 2026 19:13
Comment thread doc/api/util.md Outdated
util.types.isWeakSet(new WeakSet()); // Returns true
```
## Class: `util.URLPatternList`

@jasnell jasnell Nov 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why util when URLPattern is on url?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you're right. I misremembered.

@github-actions

Copy link
Copy Markdown
Contributor
Platform Number of requisites Proportion of new derivations
x86_64-linux 518 -> 519 => +1 2 / 519 = 0.3%
aarch64-linux 519 -> 520 => +1 2 / 520 = 0.3%
x86_64-darwin 446 -> 447 => +1 1 / 447 = 0.2%
aarch64-darwin 448 -> 449 => +1 2 / 449 = 0.4%
Total 1931 -> 1935 => +4 7 / 1935 = 0.3%
Version changes
Package Version Platforms
ada added: 4.1.1 aarch64-darwin, aarch64-linux, x86_64-darwin, x86_64-linux
ada.dev 4.0.0 -> 4.1.1 aarch64-darwin, aarch64-linux, x86_64-linux

// URLPatternList is specified in terms of URLPattern: exec() returns the
// URLPattern#exec() result of the first pattern in the list that matches, and
// test() returns whether any pattern matches. This test checks that against
// every case of the URLPattern web-platform-tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wpt in the name here is confusing. Is this ported from an actual wpt? It's not clear.

cursor Bot pushed a commit to anonrig/node that referenced this pull request Nov 27, 2026
Export URLPatternList from node:url, next to URLPattern, and keep it
off the global object. Move the tests, benchmark import, and docs
with it.

Refs: nodejs#67807
Assisted-by: Cursor Grok 4.7
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor
Platform Number of requisites Proportion of new derivations
x86_64-linux 518 -> 519 => +1 2 / 519 = 0.3%
aarch64-linux 519 -> 520 => +1 2 / 520 = 0.3%
x86_64-darwin 446 -> 447 => +1 1 / 447 = 0.2%
aarch64-darwin 448 -> 449 => +1 2 / 449 = 0.4%
Total 1931 -> 1935 => +4 7 / 1935 = 0.3%
Version changes
Package Version Platforms
ada added: 4.1.1 aarch64-darwin, aarch64-linux, x86_64-darwin, x86_64-linux
ada.dev 4.0.0 -> 4.1.1 aarch64-darwin, aarch64-linux, x86_64-linux

@anonrig anonrig changed the title util: add experimental URLPatternList url: add experimental URLPatternList Nov 27, 2026
Add url.URLPatternList, exported from node:url and not from node:util
or globalThis. It matches a URL against an ordered list of URLPattern
objects and reports the first pattern that matches. The API is
stability 1.0 (early development). It is not a standard API, and it
is not yet clear whether it will become one.

The list is implemented in C++ on the url_pattern binding and backed
by ada::url_pattern_list. The URLPattern constructor template is
cached on IsolateData. The first construction emits an
ExperimentalWarning.

Add benchmark/url/urlpatternlist-exec.js and the
test/parallel/test-urlpatternlist*.js tests. Bump the Nix shared ada
package to 4.1.1 so shared-library builds provide
ada::url_pattern_list.

Refs: whatwg/urlpattern#166
Refs: nodejs#67807
Assisted-by: Cursor Grok 4.7
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/util-urlpatternlist-30ce branch from 8918477 to 90a6fc9 Compare November 27, 2026 21:11
@github-actions

Copy link
Copy Markdown
Contributor
Platform Number of requisites Proportion of new derivations
x86_64-linux 518 -> 519 => +1 2 / 519 = 0.3%
aarch64-linux 519 -> 520 => +1 2 / 520 = 0.3%
x86_64-darwin 446 -> 447 => +1 1 / 447 = 0.2%
aarch64-darwin 448 -> 449 => +1 2 / 449 = 0.4%
Total 1931 -> 1935 => +4 7 / 1935 = 0.3%
Version changes
Package Version Platforms
ada added: 4.1.1 aarch64-darwin, aarch64-linux, x86_64-darwin, x86_64-linux
ada.dev 4.0.0 -> 4.1.1 aarch64-darwin, aarch64-linux, x86_64-linux

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Nov 27, 2026
@jasnell jasnell added the experimental Issues and PRs related to experimental features. label Nov 27, 2026
@anonrig anonrig added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 27, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 27, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@gurgunday gurgunday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@anonrig anonrig added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. experimental Issues and PRs related to experimental features. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version. typings Issues and PRs related to internal TypeScript declarations. util Issues and PRs related to the built-in util module. whatwg-url Issues and PRs related to the WHATWG URL implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants