nodejs / nodejs/node

url: URLPattern.exec() does not preserve capture group declaration order

Open
#64,734 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Version

latest main branch

Platform
7.1.4-arch1-1
Subsystem

url

What steps will reproduce the bug?
  const assert = require('node:assert');
  const { URLPattern } = require('node:url');

  const pattern = new URLPattern({
    pathname: '/:one/:two/:three',
  });

  const result = pattern.exec('https://example.com/a/b/c');

  console.log(Object.entries(result.pathname.groups));
How often does it reproduce? Is there a required condition?

Every

What is the expected behavior? Why is that the expected behavior?
  [
    ['one', 'a'],
    ['two', 'b'],
    ['three', 'c'],
  ]

URLPattern.exec() may expose named capture groups in an order different from their declaration order.

The captured values remain accessible by name, but the incorrect property insertion order is observable through Object.keys(), Object.values(), Object.entries(), object spread, and JSON serialization.

What do you see instead?

  [
    ['three', 'c'],
    ['two', 'b'],
    ['one', 'a'],
  ]
Additional information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproduction with node:url's URLPattern.exec() and inspect the resulting pathname.groups object. Trace the URLPattern implementation and its tests to identify how named groups are inserted; done means the groups appear in declaration order while remaining accessible by name, with regression coverage for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.