url: URLPattern rejects values requiring WebIDL USVString conversion for input and baseURL
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 { URL, URLPattern } = require('node:url');
const base = 'https://example.com/';
const numberPattern =
new URLPattern('https://example.com/123');
const fooPattern =
new URLPattern('https://example.com/foo');
const baseObject = {
toString() {
return base;
},
};
const baseURLObject = new URL(base);
function observe(label, callback) {
try {
console.log(label, callback());
} catch (error) {
console.log(label, error.code, error.name);
}
}
// URLPatternInput conversion.
observe(
'constructor input:',
() => new URLPattern(123, base).pathname,
);
observe(
'test input:',
() => numberPattern.test(123, base),
);
observe(
'exec input:',
() => numberPattern.exec(123, base) !== null,
);
// baseURL conversion. The three-argument constructor is intentional:
// it unambiguously selects the baseURL overload.
observe(
'constructor baseURL:',
() => new URLPattern('foo', baseObject, {}).pathname,
);
observe(
'test baseURL:',
() => fooPattern.test('foo', baseURLObject),
);
observe(
'exec baseURL:',
() => fooPattern.exec('foo', baseURLObject) !== null,
);
How often does it reproduce? Is there a required condition?
Every
What is the expected behavior? Why is that the expected behavior?
constructor input: /123
test input: true
exec input: true
constructor baseURL: /foo
test baseURL: true
exec baseURL: true
What do you see instead?
Each case throws a TypeError with code === 'ERR_INVALID_ARG_TYPE'.
Additional information
The URL Pattern IDL (https://urlpattern.spec.whatwg.org/#urlpattern) defines:
typedef (USVString or URLPatternInit) URLPatternInput;
constructor(
URLPatternInput input,
USVString baseURL,
optional URLPatternOptions options = {}
);constructor(
optional URLPatternInput input = {},
optional URLPatternOptions options = {}
);boolean test(
optional URLPatternInput input = {},
optional USVString baseURL
);URLPatternResult? exec(
optional URLPatternInput input = {},
optional USVString baseURL
);
WebIDL requires JavaScript values assigned to USVString to undergo USVString conversion
(https://webidl.spec.whatwg.org/#es-USVString), rather than already being JavaScript String values.
The constructor must first perform WebIDL overload resolution (https://webidl.spec.whatwg.org/#dfn-overload-resolution-algorithm).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the node:url URLPattern constructor, test(), and exec() entry points, then run the reproduction against the latest main branch. Compare argument handling with the cited WebIDL overload-resolution and USVString rules. Done means numeric input and object baseURL values produce the expected results instead of ERR_INVALID_ARG_TYPE, with regression coverage for the shown cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100