You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think we need clearer guidance on how to design APIs that accept URL patterns, as we've started to see some slight divergence.
Scenarios to consider:
JS APIs:
Should accept URLPattern objects
What "shorthands" / "raw inputs" can they accept? Keep in mind that URLPattern has multiple constructor forms: new URLPattern({ ...componentsDictionary, baseURL }), new URLPattern(patternString, baseURL), and then variants of each of those with another options argument.
My suggestion:
Such APIs should have a default base URL, and then accept either:
{ ...componentsDictionary } (which automatically gets the base URL),
{ ...componentsDictionary, baseURL } (overriding the base URL), or
patternString (which automatically gets the base URL).
Downsides of my suggestion:
The shorthand form can't set the options (i.e. ignoreCase)
The shorthand form can't combine a string with an overridden base URL (i.e., there is no counterpart to the new URLPattern(patternString, baseURL) constructor).
My suggestion (and what we implemented for speculation rules): the same as the "shorthands" sub-question for JS APIs.
Some of the downsides above become more serious here, because there's no new URLPattern() escape hatch; the only possible form is the "shorthand" form.
Other considerations: is there any place for pathname-only patterns? IMO probably not because anytime you match on pathname you should also allow matching on search, i.e. discriminating between URL patterns like /products/* and /product?id=* is not good. But it's come up a few times.
My proposal is to use the above rules for such situations, and enforce "pathname + search only" by checking that the resulting URL pattern's protocol/username/password/hostname/port are set to match the base URL's origin. Providing a spec helper for such a check would be a good idea, I think.
We're seeing URLPattern being used in several proposals now:
I think we need clearer guidance on how to design APIs that accept URL patterns, as we've started to see some slight divergence.
Scenarios to consider:
URLPatternobjectsURLPatternhas multiple constructor forms:new URLPattern({ ...componentsDictionary, baseURL }),new URLPattern(patternString, baseURL), and then variants of each of those with another options argument.{ ...componentsDictionary }(which automatically gets the base URL),{ ...componentsDictionary, baseURL }(overriding the base URL), orpatternString(which automatically gets the base URL).ignoreCase)new URLPattern(patternString, baseURL)constructor).new URLPattern()escape hatch; the only possible form is the "shorthand" form.Other considerations: is there any place for pathname-only patterns? IMO probably not because anytime you match on pathname you should also allow matching on search, i.e. discriminating between URL patterns like
/products/*and/product?id=*is not good. But it's come up a few times.My proposal is to use the above rules for such situations, and enforce "pathname + search only" by checking that the resulting URL pattern's protocol/username/password/hostname/port are set to match the base URL's origin. Providing a spec helper for such a check would be a good idea, I think.
/cc @sisidovski @yoshisatoyanagisawa @pmeenan @horo-t.