Skip to content

url: URLPatternInit dictionary conversion does not follow WebIDL semantics #64780

Description

@Archkon

Version

latest main branch

Platform

7.1.4-arch1-1

Subsystem

url

What steps will reproduce the bug?

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

  // Member access order
  const accessed = [];

  new URLPattern(new Proxy({}, {
    get(target, property, receiver) {
      accessed.push(property);
      return Reflect.get(target, property, receiver);
    },
  }));

  console.log(accessed);

  // Absent members in URLPatternResult.inputs
  const pattern = new URLPattern({ pathname: '/x' });
  const input = pattern.exec({ pathname: '/x' }).inputs[0];

  console.log(Object.keys(input));
  console.log('protocol' in input);
  console.log({ ...input });

How often does it reproduce? Is there a required condition?

Every

What is the expected behavior? Why is that the expected behavior?

WebIDL dictionary members should be accessed in lexicographical order:

  [
    'baseURL',
    'hash',
    'hostname',
    'password',
    'pathname',
    'port',
    'protocol',
    'search',
    'username',
  ]

The echoed dictionary should contain only members present after WebIDL conversion:

  Object.keys(input);
  // ['pathname']

  'protocol' in input;
  // false

  { ...input };
  // { pathname: '/x' }

An optional member explicitly set to undefined should also be treated as absent.

The member access-order difference affects the URLPattern constructor, exec(), and test(). The result-shape
difference is observable through URLPatternResult.inputs.

What do you see instead?

The members are accessed in the following order:

  [
    'protocol',
    'username',
    'password',
    'hostname',
    'port',
    'pathname',
    'search',
    'hash',
    'baseURL',
  ]

The echoed input exposes all dictionary members:

  Object.keys(input);
  // [
  //   'protocol',
  //   'username',
  //   'password',
  //   'hostname',
  //   'search',
  //   'hash',
  //   'baseURL',
  // ]

  'protocol' in input;
  // true

Absent members are enumerable own properties whose values are undefined.

Additional information

Refs: https://urlpattern.spec.whatwg.org/#url-pattern-match
Refs: https://webidl.spec.whatwg.org/#es-dictionary)
Refs: https://webidl.spec.whatwg.org/#idl-dictionaries
Refs: https://webidl.spec.whatwg.org/#es-dictionary)

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