@@ -7841,7 +7841,7 @@ To <dfn>get the network intercepts</dfn> given |session|, |event|, |request|, an
78417841
78427842 1. For each |url pattern| in |url patterns|:
78437843
7844- 1. If [=match URL pattern=] with |url pattern| and |url|:
7844+ 1. If [=URL pattern/match| URL pattern match =] with |url pattern| and |url|:
78457845
78467846 1. [=list/Append=] |intercept id| to |intercepts|.
78477847
@@ -8859,14 +8859,13 @@ network.UrlPattern = (
88598859
88608860network.UrlPatternPattern = {
88618861 type: "pattern",
8862- ?protocol: text,
8863- ?hostname: text,
8864- ?port: text,
8865- ?pathname: text,
8866- ?search: text,
8862+ ? protocol: text,
8863+ ? hostname: text,
8864+ ? port: text,
8865+ ? pathname: text,
8866+ ? search: text,
88678867}
88688868
8869-
88708869network.UrlPatternString = {
88718870 type: "string",
88728871 pattern: text,
@@ -8875,296 +8874,43 @@ network.UrlPatternString = {
88758874</pre>
88768875
88778876A <code>network.UrlPattern</code> represents a pattern used for matching request
8878- URLs for [=network intercepts=].
8879-
8880- When URLs are matched against a <code>network.UrlPattern</code> the URL is
8881- parsed, and each component is compared for equality with the corresponding field
8882- in the pattern, if present. Missing fields from the pattern always match.
8883-
8884- Note: This syntax is designed with future extensibility in mind. In particular
8885- the syntax forbids characters that are treated specially in the [[URLPattern]]
8886- specification. These can be escaped by prefixing them with a U+005C (\) character.
8887-
8888- <div algorithm>
8889- To <dfn>unescape URL pattern</dfn> given |pattern|
8890-
8891- 1. Let |forbidden characters| be the [=/set=] of codepoints «U+0028 ((), U+0029
8892- ()), U+002A (*), U+007B ({), U+007D (})»
8893-
8894- 1. Let |result| be the empty string.
8895-
8896- 1. Let |is escaped character| be false.
8897-
8898- 1. For each |codepoint| in |pattern|:
8899-
8900- 1. If |is escaped character| is false:
8901-
8902- 1. If |forbidden characters| [=set/contains=] |codepoint|, return [=error=]
8903- with [=error code=] [=invalid argument=].
8904-
8905- 1. If |codepoint| is U+005C (\):
8906-
8907- 1. Set |is escaped character| to true.
8908-
8909- 1. Continue.
8910-
8911- 1. Append |codepoint| to result.
8912-
8913- 1. Set |is escaped character| to false.
8914-
8915- 1. Return [=success=] with data |result|.
8916-
8917- </div>
8877+ URLs for [=network intercepts=]. URL patterns use the syntax and semantics
8878+ defined by [[!URLPattern]].
89188879
89198880<div algorithm>
89208881To <dfn>parse URL pattern</dfn>, given |pattern|:
89218882
8922- 1. Let |has protocol| be true.
8923-
8924- 1. Let |has hostname| be true.
8925-
8926- 1. Let |has port| be true.
8927-
8928- 1. Let |has pathname| be true.
8929-
8930- 1. Let |has search| be true.
8931-
893288831. If |pattern| matches the <code>network.UrlPatternPattern</code> production:
89338884
8934- 1. Let |pattern url| be the empty string.
8935-
8936- 1. If |pattern| [=map/contains=] "<code>protocol</code>":
8937-
8938- 1. If |pattern|["<code>protocol</code>"] is the empty string, return [=error=]
8939- with [=error code=] [=invalid argument=].
8940-
8941- 1. Let |protocol| be the result of [=trying=] to [=unescape
8942- URL Pattern=] with |pattern|["<code>protocol</code>"].
8943-
8944- 1. For each |codepoint| in |protocol|:
8945-
8946- 1. If |codepoint| is not [=ASCII alphanumeric=] and «U+002B (+), U+002D
8947- (-), U+002E (.)» does not [=set/contains|contain=] |codepoint|:
8948-
8949- 1. Return [=error=] with [=error code=] invalid argument.
8885+ 1. Let |init| be a new {{URLPatternInit}}.
89508886
8951- 1. Append |protocol| to |pattern url|.
8887+ 1. If |pattern| [=map/contains=] "<code>protocol</code>", set
8888+ |init|["<code>protocol</code>"] to |pattern|["<code>protocol</code>"].
89528889
8953- 1. Otherwise:
8954-
8955- 1. Set |has protocol| to false.
8956-
8957- 1. Append "<code>http</code>" to |pattern url|.
8958-
8959- 1. Let |scheme| be [=ASCII lowercase=] with |pattern url|.
8960-
8961- 1. Append "<code>:</code>" to |pattern url|.
8962-
8963- 1. If |scheme| [=is special=], append "<code>//</code>" to |pattern url|.
8964-
8965- 1. If |pattern| [=map/contains=] "<code>hostname</code>":
8966-
8967- 1. If |pattern|["<code>hostname</code>"] is the empty string, return [=error=]
8968- with [=error code=] [=invalid argument=].
8969-
8970- 1. If |scheme| is "<code>file</code>" return [=error=] with [=error code=]
8971- [=invalid argument=].
8972-
8973- 1. Let |hostname| be the result of [=trying=] to [=unescape
8974- URL Pattern=] with |pattern|["<code>hostname</code>"].
8975-
8976- 1. Let |inside brackets| be false.
8977-
8978- 1. For each |codepoint| in |hostname|:
8979-
8980- 1. If «U+002F (/), U+003F (?), U+0023 (#)» [=set/contains=]
8981- |codepoint|:
8982-
8983- 1. Return [=error=] with [=error code=] [=invalid argument=].
8984-
8985- 1. If |inside brackets| is false and |codepoint| is U+003A (:):
8986-
8987- 1. Return [=error=] with [=error code=] [=invalid argument=].
8890+ 1. If |pattern| [=map/contains=] "<code>hostname</code>", set
8891+ |init|["<code>hostname</code>"] to |pattern|["<code>hostname</code>"].
89888892
8989- 1. If |codepoint| is U+005B ([), set |inside brackets| to true.
8893+ 1. If |pattern| [=map/contains=] "<code>port</code>", set
8894+ |init|["<code>port</code>"] to |pattern|["<code>port</code>"].
89908895
8991- 1. If |codepoint| is U+005D (]), set |inside brackets| to false.
8992-
8993- 1. Append |hostname| to |pattern url|.
8994-
8995- 1. Otherwise:
8996-
8997- 1. If |scheme| is not "<code>file</code>", append "<code>placeholder</code>" to
8998- |pattern url|.
8999-
9000- 1. Set |has hostname| to false.
9001-
9002- 1. If |pattern| [=map/contains=] "<code>port</code>":
9003-
9004- 1. If |pattern|["<code>port</code>"] is the empty string, return [=error=]
9005- with [=error code=] [=invalid argument=].
9006-
9007- 1. Let |port| be the result of [=trying=] to [=unescape
9008- URL Pattern=] with |pattern|["<code>port</code>"].
9009-
9010- 1. Append "<code>:</code>" to |pattern url|.
9011-
9012- 1. For each |codepoint| in |port|:
9013-
9014- 1. If |codepoint| is not an [=ASCII digit=]:
9015-
9016- 1. Return [=error=] with [=error code=] [=invalid argument=].
9017-
9018- 1. Append |port| to |pattern url|.
9019-
9020- 1. Otherwise:
8896+ 1. If |pattern| [=map/contains=] "<code>pathname</code>", set
8897+ |init|["<code>pathname</code>"] to |pattern|["<code>pathname</code>"].
90218898
9022- 1. Set |has port| to false.
8899+ 1. If |pattern| [=map/contains=] "<code>search</code>", set
8900+ |init|["<code>search</code>"] to |pattern|["<code>search</code>"].
90238901
9024- 1. If |pattern| [=map/contains=] "<code>pathname</code>":
9025-
9026- 1. Let |pathname| be the result of [=trying=] to [=unescape URL Pattern=] with
9027- |pattern|["<code>pathname</code>"].
9028-
9029- 1. If |pathname| does not [=string/starts with|start with=] U+002F (/), then
9030- append "<code>/</code>" to |pattern url|.
9031-
9032- 1. For each |codepoint| in |pathname|:
9033-
9034- 1. If «U+003F (?), U+0023 (#)» [=set/contains=]
9035- |codepoint|:
9036-
9037- 1. Return [=error=] with [=error code=] [=invalid argument=].
9038-
9039- 1. Append |pathname| to |pattern url|.
9040-
9041- 1. Otherwise:
9042-
9043- 1. Set |has pathname| to false.
9044-
9045- 1. If |pattern| [=map/contains=] "<code>search</code>":
9046-
9047- 1. Let |search| be the result of [=trying=] to [=unescape URL pattern=] with
9048- |pattern|["<code>search</code>"].
9049-
9050- 1. If |search| does not [=string/starts with|start with=] U+003F (?), then
9051- append "<code>?</code>" to |pattern url|.
9052-
9053- 1. For each |codepoint| in |search|:
9054-
9055- 1. If |codepoint| is U+0023 (#):
9056-
9057- 1. Return [=error=] with [=error code=] [=invalid argument=].
9058-
9059- 1. Append |search| to |pattern url|.
9060-
9061- 1. Otherwise:
9062-
9063- 1. Set |has search| to false.
8902+ 1. Let |url pattern| be the result of
8903+ [=URL pattern/create|creating a URLPattern=] given |init|.
90648904
906589051. Otherwise, if |pattern| matches the <code>network.UrlPatternString</code> production:
90668906
9067- 1. Let |pattern url| be the result of [=trying=] to [=unescape URL
9068- pattern=] with |pattern|["<code>pattern</code>"].
9069-
9070- 1. Let |url| be the result of [=URL Parser|parsing=] |pattern url|.
9071-
9072- 1. If |url| is failure, return [=error=] with [=error code=] [=invalid argument=].
9073-
9074- 1. Let |parsed| be a struct with the following fields:
9075- <dl>
9076- <dt>protocol
9077- <dd>|url|'s [=url/scheme=] if |has protocol| is true, or null otherwise.
9078- <dt>hostname
9079- <dd>|url|'s [=url/host=] if |has hostname| is true, or null otherwise.
9080- <dt>port
9081- <dd>
9082- 1. If |has port| is false:
9083-
9084- 1. null.
9085-
9086- 1. Otherwise:
9087-
9088- 1. If |url|'s [=url/scheme=] [=is special=] and |url|'s [=url/scheme=]'s
9089- [=default port=] is not null, and |url|'s [=url/port=] is null or is
9090- equal to [=url/scheme=]'s [=default port=]:
9091-
9092- 1. The empty string.
9093-
9094- 1. Otherwise, if |url|'s [=url/port=] is not null:
9095-
9096- 1. [=Serialize an integer=] with |url|'s [=url/port=].
9097-
9098- 1. Otherwise:
9099-
9100- 1. null.
8907+ 1. Let |url pattern| be the result of [=URL pattern/create|creating a URLPattern=]
8908+ given |pattern|["<code>pattern</code>"].
91018909
9102- <dt>pathname
9103- <dd>
9104- 1. If |has pathname| is false:
9105-
9106- 1. null.
9107-
9108- 1. Otherwise:
9109-
9110- 1. The result of running the [=URL path serializer=] with |url|, if
9111- |url|'s [=url/path=] is not the empty string and is not [=list/empty=],
9112- or null otherwise.
9113-
9114- <dt>search
9115- <dd>
9116- 1. If |has search| is false:
9117-
9118- 1. null.
9119-
9120- 1. Otherwise:
9121-
9122- 1. The empty string if |url|'s [=url/query=] is null, or |url|'s [=url/query=] otherwise.
9123- </dl>
9124-
9125- 1. Return [=success=] with data |parsed|.
9126-
9127- </div>
9128-
9129- <div algorithm>
9130- To <dfn>match URL pattern</dfn> given |url pattern| and |url string|:
9131-
9132- 1. Let |url| be the result of [=URL parser|parsing=] |url string|.
9133-
9134- 1. If |url pattern|'s protocol is not null and is not equal to |url|'s
9135- [=url/scheme=], return false.
9136-
9137- 1. If |url pattern|'s hostname is not null and is not equal to |url|'s
9138- [=url/host=], return false.
9139-
9140- 1. If |url pattern|'s port is not null:
9141-
9142- 1. Let |port| be null.
9143-
9144- 1. If |url|'s [=url/scheme=] [=is special=] and |url|'s
9145- [=url/scheme=]'s [=default port=] is not null, and |url|'s [=url/port=] is
9146- null or is equal to [=url/scheme=]'s [=default port=]:
9147-
9148- 1. Set |port| to the empty string.
9149-
9150- 1. Otherwise, if |url|'s [=url/port=], is not null:
9151-
9152- 1. Set |port| to [=serialize an integer=] with |url|'s [=url/port=].
9153-
9154- 1. If |url pattern|'s port is not equal to |port|, return false.
9155-
9156- 1. If |url pattern|'s pathname is not null and is not equal to the result of
9157- running the [=URL path serializer=] with |url|, return false.
9158-
9159- 1. If |url pattern|'s search is not null:
9160-
9161- 1. Let |url query| be |url|'s [=url/query=].
9162-
9163- 1. If |url query| is null, set |url query| to the empty string.
9164-
9165- 1. If |url pattern|'s search is not equal to |url query|, return false.
8910+ 1. If |url pattern| is failure, return [=error=] with [=error code=]
8911+ [=invalid argument=].
91668912
9167- 1. Return true .
8913+ 1. Return [=success=] with data |url pattern| .
91688914
91698915</div>
91708916
0 commit comments