Skip to content

Commit

Permalink
Introduce changes upon whatwg/urlpattern#199.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshisatoyanagisawa committed Nov 30, 2023
1 parent 0a553af commit bdc2474
Showing 1 changed file with 11 additions and 50 deletions.
61 changes: 11 additions & 50 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ spec: urlpattern; urlPrefix: https://wicg.github.io/urlpattern/
<pre class="idl">
[Exposed=ServiceWorker]
interface InstallEvent : ExtendableEvent {
Promise&lt;undefined&gt; registerRouter((RouterRule or sequence&lt;RouterRule&gt;) rules);
Promise&lt;undefined&gt; addRoutes((RouterRule or sequence&lt;RouterRule&gt;) rules);
};

dictionary RouterRule {
Expand All @@ -1578,24 +1578,24 @@ spec: urlpattern; urlPrefix: https://wicg.github.io/urlpattern/
};

dictionary RouterCondition {
USVString urlPattern;
URLPatternCompatible urlPattern;
};

enum RouterSourceEnum { "network" };
enum RouterSource { "network" };
</pre>

Each {{RouterCondition/urlPattern}} object has an associated <dfn>URLPattern</dfn>, a {{URLPattern}}, which is initially unset.

<section>
<h4 id="register-router-method">{{InstallEvent/registerRouter(rules)|event.registerRouter(rules)}}</h4>
<h4 id="register-router-method">{{InstallEvent/addRoutes(rules)|event.addRoutes(rules)}}</h4>

{{InstallEvent/registerRouter(rules)}} registers this service worker the rules to offload simple tasks that the fetch handler does.
{{InstallEvent/addRoutes(rules)}} registers this service worker the rules to offload simple tasks that the fetch handler does.

<dfn method for="InstallEvent"><code>registerRouter(|rules|)</code></dfn> method *must* run these steps:
<dfn method for="InstallEvent"><code>addRoutes(|rules|)</code></dfn> method *must* run these steps:

1. Let |routerRules| be a list of {{RouterRule}} dictionaries.
1. If |rules| is a {{RouterRule}} dictionary, set |rules| to &#x00AB; |rules| &#x00BB;.
1. for each |rule| in |rules|:
1. For each |rule| of |rules|:
1. If running [=VerifyRouterRule=] algorithm with |rule| and [=/service worker=] returns false, <a>throw</a> a <code>TypeError</code>.
1. Append |rule| to |routerRules|.
1. Set [=/service worker=]'s [=static router rules object=] to |routerRules|.
Expand Down Expand Up @@ -3244,52 +3244,13 @@ spec: urlpattern; urlPrefix: https://wicg.github.io/urlpattern/
: Output
:: a boolean

1. If |rule|["{{RouterRule/condition}}"]["{{RouterCondition/urlPattern}}"] is the empty string, return false.
1. Let |rawPattern| be |rule|["{{RouterRule/condition}}"]["{{RouterCondition/urlPattern}}"].
1. If |rawPattern| is a [=string=], then:
1. Let |baseURL| be |serviceWorker|'s [=service worker/script url=].
1. Set |pattern| to the result of constructing a {{URLPattern}} using the {{URLPattern/URLPattern(input, baseURL)}} constructor steps given |rawPattern| and |baseURL|. If those steps throw, catch the exception and return false.
1. Otherwise, if |rawPattern| is {{URLPatternInit}}:
1. Set |pattern| to the result of constructing a {{URLPattern}} using the {{URLPattern/URLPattern(input)}} constructor steps given |rawPattern|. If those steps throw, catch the exception and return false.
1. Otherwise, return false.
1. If running the [=VerifyURLPattern=] algorithm with |pattern| returns false, return false.
1. Set |rule|["{{RouterRule/condition}}"]["{{RouterCondition/urlPattern}}"]'s associated {{URLPattern}} to |pattern|.
1. Return true.
</section>

<section algorithm>
<h3 id="verify-urlpattern-algorithm"><dfn>VerifyURLPattern</dfn></h3>

: Input
:: |pattern|, a {{URLPattern}}
: Output
:: a boolean

1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/protocol component=] returns false, return false.
1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/username component=] returns false, return false.
1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/password component=] returns false, return false.
1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/hostname component=] returns false, return false.
1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/port component=] returns false, return false.
1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/pathname component=] returns false, return false.
1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/search component=] returns false, return false.
1. If running the [=VerifyURLPatternComponent=] algorithm with |pattern|'s [=urlpattern/hash component=] returns false, return false.
1. Return true.
</section>
1. Let |pattern| be the result of [=building a URLPattern from a Web IDL value=] |rawPattern| given |baseURL| and |serivceWorker|'s [=service worker/global object=]'s [=relevant realm=]. If this throws an exception, catch it and return false.
1. If |pattern| [=URLPattern/has regexp groups=] returns true, return false.

<section algorithm>
<h3 id="verify-urlpattern-component-algorithm"><dfn>VerifyURLPatternComponent</dfn></h3>

: Input
:: |component|, a [=component=].
: Output
:: a boolean

1. Let |parts| be a result of [=urlpattern/parsing=] |component|'s associated [=urlpattern-component/pattern string=].
1. [=list/For each=] |part| of |parts|:
1. If |part|'s [=urlpattern-part/type=] is "<code>regexp</code>", return false.

Note: Since running a user-defined regular expression has a security concern, it is prohibited.
Note: Since running a user-defined regular expression has a security concern, it is prohibited.

1. Set |rule|["{{RouterRule/condition}}"]["{{RouterCondition/urlPattern}}"]'s associated {{URLPattern}} to |pattern|.
1. Return true.
</section>

Expand Down

0 comments on commit bdc2474

Please sign in to comment.