url: URLPattern rejects values requiring WebIDL USVString conversion for input and baseURL
Personne n'a encore pris cette issue.
- Langage dominant
- JavaScript
- Étoiles
- 122k
- Forks
- 37.3k
- Merge moyen
- 4 j 2 h
- PR mergées (30 j)
- 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).
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par les points d’entrée du constructeur node:url URLPattern, de test() et de exec(), puis exécutez la reproduction sur la branche main la plus récente. Comparez la gestion des arguments avec les règles citées de résolution de surcharge WebIDL et de USVString. C’est terminé lorsque les entrées numériques et les valeurs object baseURL produisent les résultats attendus au lieu de ERR_INVALID_ARG_TYPE, avec une couverture de régression pour les cas présentés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, nodejs
- Domaine
- api, backend
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 48/100