Description
What is the issue with the URL Pattern Standard?
A correct implementation of the current spec fail with this kind of simple input:
new URLPattern({ pathname: '/books/:id', baseURL: 'https://example.com' });
The issue comes in part from the use of URL spec's internal parsers. These parsers manipulate URL records with some fields (host, port, query, fragment) that default to null
when empty.
When those empty fields are then used to fill the default url pattern (step 11-7 to 11-10 of process a URLPatternInit), the processing a base URL string assertion fail (Assert: input is not null.)
In the special case of the baseURL port, URL record use unsigned integers and not strings, so the assertion pass but the code fail further down in escape a pattern string (1. Assert: input is an ASCII string.).
As per Web IDL, implicit string conversion would yield "null"
for those empty field (as the URL record struct is not marked [LegacyNullToEmptyString]
) which is not what we want.
The spec should check if a baseURL field is not null
before using it to fill the url pattern. As for the port it should be converted to a string but is the processing of the stringified port really necessary as we are certain its only ASCII characters and there's nothing to escape ?).