-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a "using URLPattern in other APIs" section #182
Comments
I think supporting this might give you URLPattern objects "for free" because the components are exposed as properties with the same names, much like how many Foo interfaces satisfy the corresponding FooInit dictionary.
FWIW, shorthands not having all capabilities seems fine to me.
The natural base URL is almost always the response URL (or request URL, for request headers), right?
+1, though I'm not even sure how often we'll need spec text, as I'd expect in practice the pattern never matching will cause no behavior. So it might just amount to non-normative text advising a warning if the pattern cannot possibly match (because it doesn't match the origin's scheme/host/port, because it doesn't see fragments but the pattern requires a non-empty fragment, etc). |
Thank you for raising this.
In WICG/compression-dictionary-transport#51 (comment), the new option to
I understand we'd like to have pathname+search match in the most case, but is this enforcement applied only when the base URL was added automatically? Service worker static routing may accept matching other URLPatternInit items such as hostname, since it handles cross origin resources etc. |
One of the other things we'd need when integrating with other specs is an agreed-upon way to specify which tokens are supported. Specifically if |
Do you have a plan to make URLPattern gets an implicit baseURL? Moreover, I expect URLPatternInit and the URLPattern interface has the IgnoreCase field. It is important information for the matching, and should be respected in the evaluator. A flag to ask URLPattern to prevent regexp might need to be used at the compile time, and it might not need to be passed to the evaluator. I think it nice to make URLPattern API options to support the flag. It is also helpful for the people to understand the behavior with |
No. And I don't think this is the right question to be asking. Consider how other web platform APIs behave. This pattern is widespread. Almost every web API (maybe every, now?) comes with an implicit base URL. We don't build the concept of implicit base URL into the When designing URL patterns and related APIs, how URLs and related APIs work is generally a good precedent.
I don't think this is the right expectation. Additionally, if you want the full power of the I don't think this will be confusing for web developers, in the same way that web developers don't find
If you want
I think adding this at the We should make it easy to specify this prohibition. For example, there should be a specification hook like If we want to expose this as a web developer-facing API, we could do so: then web developers could emulate the behavior of speculations using |
Since USVString does not pattern match with URLs with query strings or hashtags, the example code has been changed to patterns without them. Also, the short-hand form is under the discussion in whatwg/urlpattern#182, I intend to avoid the examples affected by the result.
I thought that the urlPattern condition in the static routing API would take two kinds of arguments and made it accept URLpatternInput, but it sounds three; USVString, a dictionary for short-hands, and URLPattern object. Upon the past discussion, I misunderstood that you meant passing a dictionary should behave equivalent to passing URLPattern object, but it sounds not. i.e. By the way, I hope #179 is resolved soon. Until that is resolved, I believe it is bad idea to introduce implicit baseURL because it brings unexpected surprises like not matching URLs with query strings, which would commonly happens.
How the WebIDL for the urlPattern condition's argument would be?
My goal is not adding the flag but helping developers to recognize un-intended regular expression usage. Therefore, |
Agreed. I think it is very reasonable to avoid introducing implicit base URL into service worker static routes until we resolve that. I think @jeremyroman will be working on it soon.
I think it would be:
This is reasonable. Perhaps we should open a new issue, which you or @sisidovski could send a pull request on, for such a proposal? |
Thank you.
I have filed #191 |
This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition accepts the URLPatternInit object. Before this CL, the URLPatternInit input is accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, which the SW script URL is internally used when adding the new router rule. So some missing components will use the values inherited from the baseURL in that case. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if not provided. It typically happens when the input is an object that complies with the URLPatterInit interface. On the other hand, it wouldn't affect the case when URLPatternInit is the output of `new URLPattern()`. Thank to the recent change on the URLPattern[1], the constructed components in URLPatternInit will inherit or wildcarded. baseURL won't override components if those are not empty. This behavior change is based on the discussion in whatwg/urlpattern#182. [1] whatwg/urlpattern#198 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b
This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition accepts the URLPatternInit object. Before this CL, the URLPatternInit input is accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, which the SW script URL is internally used when adding the new router rule. So some missing components will use the values inherited from the baseURL in that case. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if not provided. It typically happens when the input is an object that complies with the URLPatterInit interface. On the other hand, it wouldn't affect the case when URLPatternInit is the output of `new URLPattern()`. Thank to the recent change on the URLPattern[1], the constructed components in URLPatternInit will inherit or wildcarded. baseURL won't override components if those are not empty. This behavior change is based on the discussion in whatwg/urlpattern#182. [1] whatwg/urlpattern#198 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b
This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. This behavior change is based on the discussion in whatwg/urlpattern#182. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b
This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b
This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b
This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b
This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5039680 Reviewed-by: Takashi Toyoshima <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Shunya Shishido <[email protected]> Reviewed-by: Yoshisato Yanagisawa <[email protected]> Auto-Submit: Shunya Shishido <[email protected]> Cr-Commit-Position: refs/heads/main@{#1229724}
This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5039680 Reviewed-by: Takashi Toyoshima <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Shunya Shishido <[email protected]> Reviewed-by: Yoshisato Yanagisawa <[email protected]> Auto-Submit: Shunya Shishido <[email protected]> Cr-Commit-Position: refs/heads/main@{#1229724}
This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5039680 Reviewed-by: Takashi Toyoshima <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Shunya Shishido <[email protected]> Reviewed-by: Yoshisato Yanagisawa <[email protected]> Auto-Submit: Shunya Shishido <[email protected]> Cr-Commit-Position: refs/heads/main@{#1229724}
Such a section has been added. Since the original issue comment mentioned HTTP headers which are still in discussion, leaving this issue thread open for now. |
…while routing rule registration, a=testonly Automatic update from web-platform-tests Add baseURL to the URLPattern condition while routing rule registration This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5039680 Reviewed-by: Takashi Toyoshima <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Shunya Shishido <[email protected]> Reviewed-by: Yoshisato Yanagisawa <[email protected]> Auto-Submit: Shunya Shishido <[email protected]> Cr-Commit-Position: refs/heads/main@{#1229724} -- wpt-commits: ffe06ef95d4d48be147e640fd9d1c489b810f929 wpt-pr: 43272
…while routing rule registration, a=testonly Automatic update from web-platform-tests Add baseURL to the URLPattern condition while routing rule registration This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5039680 Reviewed-by: Takashi Toyoshima <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Commit-Queue: Shunya Shishido <[email protected]> Reviewed-by: Yoshisato Yanagisawa <[email protected]> Auto-Submit: Shunya Shishido <[email protected]> Cr-Commit-Position: refs/heads/main@{#1229724} -- wpt-commits: ffe06ef95d4d48be147e640fd9d1c489b810f929 wpt-pr: 43272
…while routing rule registration, a=testonly Automatic update from web-platform-tests Add baseURL to the URLPattern condition while routing rule registration This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5039680 Reviewed-by: Takashi Toyoshima <toyoshimchromium.org> Reviewed-by: Kouhei Ueno <kouheichromium.org> Commit-Queue: Shunya Shishido <sisidovskichromium.org> Reviewed-by: Yoshisato Yanagisawa <yyanagisawachromium.org> Auto-Submit: Shunya Shishido <sisidovskichromium.org> Cr-Commit-Position: refs/heads/main{#1229724} -- wpt-commits: ffe06ef95d4d48be147e640fd9d1c489b810f929 wpt-pr: 43272 UltraBlame original commit: 8cba5e465039e56ad23ca65c4e4b1c307f2f8379
…while routing rule registration, a=testonly Automatic update from web-platform-tests Add baseURL to the URLPattern condition while routing rule registration This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5039680 Reviewed-by: Takashi Toyoshima <toyoshimchromium.org> Reviewed-by: Kouhei Ueno <kouheichromium.org> Commit-Queue: Shunya Shishido <sisidovskichromium.org> Reviewed-by: Yoshisato Yanagisawa <yyanagisawachromium.org> Auto-Submit: Shunya Shishido <sisidovskichromium.org> Cr-Commit-Position: refs/heads/main{#1229724} -- wpt-commits: ffe06ef95d4d48be147e640fd9d1c489b810f929 wpt-pr: 43272 UltraBlame original commit: 8cba5e465039e56ad23ca65c4e4b1c307f2f8379
…while routing rule registration, a=testonly Automatic update from web-platform-tests Add baseURL to the URLPattern condition while routing rule registration This behavior change was originally started in whatwg/urlpattern#182, and follows the spec change in whatwg/urlpattern#199. This CL changes the behavior of the router rule registration in the ServiceWorker Static Routing API, especially when the |urlPattern| condition receives URLPatternInit or USVString. Before this CL, the URLPatternInit input was accepted as it is, that means any unspecified fields are resulted in the wildcards (*). This behavior is inconsistent with the case when |urlPattern| accepts a string. When a string is passed, missing fields are complemented by baseURL, the SW script URL is internally treated as baseURL. After this CL, the URLPatternInit input also internally uses the SW script URL as a baseURL if it's not explicitly provided. This is achieved by the helper method `URLPattern::From()`, which was added in [1]. This change doesn't affect the case when the input is URLPattern, which means the input is the object constructed via `new URLPattern()`. [1] crrev.com/c/5053645 Bug: 1371756 Change-Id: I5cce80fde05cf18237c8b6412b00e017ff5aad5b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5039680 Reviewed-by: Takashi Toyoshima <toyoshimchromium.org> Reviewed-by: Kouhei Ueno <kouheichromium.org> Commit-Queue: Shunya Shishido <sisidovskichromium.org> Reviewed-by: Yoshisato Yanagisawa <yyanagisawachromium.org> Auto-Submit: Shunya Shishido <sisidovskichromium.org> Cr-Commit-Position: refs/heads/main{#1229724} -- wpt-commits: ffe06ef95d4d48be147e640fd9d1c489b810f929 wpt-pr: 43272 UltraBlame original commit: 8cba5e465039e56ad23ca65c4e4b1c307f2f8379
I'll note that https://datatracker.ietf.org/doc/draft-ietf-httpbis-compression-dictionary/17/ ends up explicitly instantiating URLPattern classes during HTTP header processing, which is somewhat confusing since, e.g., it doesn't talk about which JavaScript realm to use. It might be good to provide a better interface for HTTP header specs to use soon, if we can... |
The existing dfns should be enough to avoid using the WebIDL integration (as the JSON section demonstrates), but still maybe explicitly calling out HTTP headers makes it more straightforward. |
Per discussion on whatwg#182 some text explaining this would be useful.
Sorry about that. I just published draft-18 of the compression dictionaries ID which switches away from using the WebIDL and better mirrors what the JSON section demonstrates. FWIW, it might be easier to reference if each of the High-level operations sections had a discrete sub-section. Right now the text version of the ID relies on "create", "match" and "has regexp groups" for each of the sections but it's not necessarily obvious when coming to the spec that that's the part of the document that is referred to (the HTML version has a deep link which makes it easier). |
Thanks, but I think the direct links to create work better for my use case since it already takes care of asserting the field as a structured field as part of the processing. |
Per discussion on #182 some text explaining this would be useful. This mostly consists of advice since the useful algorithms are already exposed.
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:
URLPattern
objectsURLPattern
has 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.
The text was updated successfully, but these errors were encountered: