Skip to content

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

Description

@Archkon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions