diff --git a/index.bs b/index.bs index 1ccfd5704..05733e57f 100644 --- a/index.bs +++ b/index.bs @@ -7841,7 +7841,7 @@ To get the network intercepts given |session|, |event|, |request|, an 1. For each |url pattern| in |url patterns|: - 1. If [=match URL pattern=] with |url pattern| and |url|: + 1. If [=URL pattern/match|URL pattern match=] with |url pattern| and |url|: 1. [=list/Append=] |intercept id| to |intercepts|. @@ -8859,14 +8859,13 @@ network.UrlPattern = ( network.UrlPatternPattern = { type: "pattern", - ?protocol: text, - ?hostname: text, - ?port: text, - ?pathname: text, - ?search: text, + ? protocol: text, + ? hostname: text, + ? port: text, + ? pathname: text, + ? search: text, } - network.UrlPatternString = { type: "string", pattern: text, @@ -8874,297 +8873,57 @@ network.UrlPatternString = { -A network.UrlPattern represents a pattern used for matching request -URLs for [=network intercepts=]. - -When URLs are matched against a network.UrlPattern the URL is -parsed, and each component is compared for equality with the corresponding field -in the pattern, if present. Missing fields from the pattern always match. - -Note: This syntax is designed with future extensibility in mind. In particular -the syntax forbids characters that are treated specially in the [[URLPattern]] -specification. These can be escaped by prefixing them with a U+005C (\) character. - -
-To unescape URL pattern given |pattern| - -1. Let |forbidden characters| be the [=/set=] of codepoints «U+0028 ((), U+0029 - ()), U+002A (*), U+007B ({), U+007D (})» - -1. Let |result| be the empty string. - -1. Let |is escaped character| be false. - -1. For each |codepoint| in |pattern|: - - 1. If |is escaped character| is false: - - 1. If |forbidden characters| [=set/contains=] |codepoint|, return [=error=] - with [=error code=] [=invalid argument=]. - - 1. If |codepoint| is U+005C (\): - - 1. Set |is escaped character| to true. - - 1. Continue. - - 1. Append |codepoint| to result. +Issue(1109): Add support for additional {{URLPatternInit}} fields (e.g. +baseURL, username, password, +hash) and parse options (e.g. ignoreCase). - 1. Set |is escaped character| to false. - -1. Return [=success=] with data |result|. +A network.UrlPattern represents a pattern used for matching request +URLs for [=network intercepts=]. URL patterns use the syntax and semantics +defined by [[!URLPattern]]. -
+Note: The component fields of network.UrlPatternPattern and the +pattern field of network.UrlPatternString are parsed +using [[!URLPattern]] syntax. Characters such as *, ++, ?, :, and +{...} have special meaning as wildcards, modifiers, +named groups, and grouping constructs respectively. To match these characters +literally, prefix them with a backslash.
To parse URL pattern, given |pattern|: -1. Let |has protocol| be true. - -1. Let |has hostname| be true. - -1. Let |has port| be true. - -1. Let |has pathname| be true. - -1. Let |has search| be true. - 1. If |pattern| matches the network.UrlPatternPattern production: - 1. Let |pattern url| be the empty string. - - 1. If |pattern| [=map/contains=] "protocol": - - 1. If |pattern|["protocol"] is the empty string, return [=error=] - with [=error code=] [=invalid argument=]. - - 1. Let |protocol| be the result of [=trying=] to [=unescape - URL Pattern=] with |pattern|["protocol"]. - - 1. For each |codepoint| in |protocol|: - - 1. If |codepoint| is not [=ASCII alphanumeric=] and «U+002B (+), U+002D - (-), U+002E (.)» does not [=set/contains|contain=] |codepoint|: - - 1. Return [=error=] with [=error code=] invalid argument. - - 1. Append |protocol| to |pattern url|. - - 1. Otherwise: - - 1. Set |has protocol| to false. - - 1. Append "http" to |pattern url|. - - 1. Let |scheme| be [=ASCII lowercase=] with |pattern url|. - - 1. Append ":" to |pattern url|. - - 1. If |scheme| [=is special=], append "//" to |pattern url|. - - 1. If |pattern| [=map/contains=] "hostname": - - 1. If |pattern|["hostname"] is the empty string, return [=error=] - with [=error code=] [=invalid argument=]. - - 1. If |scheme| is "file" return [=error=] with [=error code=] - [=invalid argument=]. - - 1. Let |hostname| be the result of [=trying=] to [=unescape - URL Pattern=] with |pattern|["hostname"]. - - 1. Let |inside brackets| be false. - - 1. For each |codepoint| in |hostname|: - - 1. If «U+002F (/), U+003F (?), U+0023 (#)» [=set/contains=] - |codepoint|: - - 1. Return [=error=] with [=error code=] [=invalid argument=]. - - 1. If |inside brackets| is false and |codepoint| is U+003A (:): - - 1. Return [=error=] with [=error code=] [=invalid argument=]. - - 1. If |codepoint| is U+005B ([), set |inside brackets| to true. - - 1. If |codepoint| is U+005D (]), set |inside brackets| to false. - - 1. Append |hostname| to |pattern url|. - - 1. Otherwise: - - 1. If |scheme| is not "file", append "placeholder" to - |pattern url|. - - 1. Set |has hostname| to false. - - 1. If |pattern| [=map/contains=] "port": - - 1. If |pattern|["port"] is the empty string, return [=error=] - with [=error code=] [=invalid argument=]. - - 1. Let |port| be the result of [=trying=] to [=unescape - URL Pattern=] with |pattern|["port"]. - - 1. Append ":" to |pattern url|. - - 1. For each |codepoint| in |port|: - - 1. If |codepoint| is not an [=ASCII digit=]: + 1. Let |init| be a new {{URLPatternInit}}. - 1. Return [=error=] with [=error code=] [=invalid argument=]. + 1. If |pattern| [=map/contains=] "protocol", set + |init|["protocol"] to |pattern|["protocol"]. - 1. Append |port| to |pattern url|. + 1. If |pattern| [=map/contains=] "hostname", set + |init|["hostname"] to |pattern|["hostname"]. - 1. Otherwise: - - 1. Set |has port| to false. - - 1. If |pattern| [=map/contains=] "pathname": - - 1. Let |pathname| be the result of [=trying=] to [=unescape URL Pattern=] with - |pattern|["pathname"]. - - 1. If |pathname| does not [=string/starts with|start with=] U+002F (/), then - append "/" to |pattern url|. - - 1. For each |codepoint| in |pathname|: - - 1. If «U+003F (?), U+0023 (#)» [=set/contains=] - |codepoint|: - - 1. Return [=error=] with [=error code=] [=invalid argument=]. - - 1. Append |pathname| to |pattern url|. - - 1. Otherwise: - - 1. Set |has pathname| to false. - - 1. If |pattern| [=map/contains=] "search": - - 1. Let |search| be the result of [=trying=] to [=unescape URL pattern=] with - |pattern|["search"]. - - 1. If |search| does not [=string/starts with|start with=] U+003F (?), then - append "?" to |pattern url|. - - 1. For each |codepoint| in |search|: + 1. If |pattern| [=map/contains=] "port", set + |init|["port"] to |pattern|["port"]. - 1. If |codepoint| is U+0023 (#): + 1. If |pattern| [=map/contains=] "pathname", set + |init|["pathname"] to |pattern|["pathname"]. - 1. Return [=error=] with [=error code=] [=invalid argument=]. + 1. If |pattern| [=map/contains=] "search", set + |init|["search"] to |pattern|["search"]. - 1. Append |search| to |pattern url|. - - 1. Otherwise: - - 1. Set |has search| to false. + 1. Let |url pattern| be the result of + [=URL pattern/create|creating a URLPattern=] given |init|, null, and an + empty [=/map=]. If this throws an exception, return [=error=] with + [=error code=] [=invalid argument=]. 1. Otherwise, if |pattern| matches the network.UrlPatternString production: - 1. Let |pattern url| be the result of [=trying=] to [=unescape URL - pattern=] with |pattern|["pattern"]. - -1. Let |url| be the result of [=URL Parser|parsing=] |pattern url|. - -1. If |url| is failure, return [=error=] with [=error code=] [=invalid argument=]. - -1. Let |parsed| be a struct with the following fields: -
-
protocol -
|url|'s [=url/scheme=] if |has protocol| is true, or null otherwise. -
hostname -
|url|'s [=url/host=] if |has hostname| is true, or null otherwise. -
port -
- 1. If |has port| is false: - - 1. null. - - 1. Otherwise: - - 1. If |url|'s [=url/scheme=] [=is special=] and |url|'s [=url/scheme=]'s - [=default port=] is not null, and |url|'s [=url/port=] is null or is - equal to [=url/scheme=]'s [=default port=]: - - 1. The empty string. - - 1. Otherwise, if |url|'s [=url/port=] is not null: - - 1. [=Serialize an integer=] with |url|'s [=url/port=]. - - 1. Otherwise: + 1. Let |url pattern| be the result of [=URL pattern/create|creating a URLPattern=] + given |pattern|["pattern"], null, and an empty [=/map=]. If + this throws an exception, return [=error=] with [=error code=] + [=invalid argument=]. - 1. null. - -
pathname -
- 1. If |has pathname| is false: - - 1. null. - - 1. Otherwise: - - 1. The result of running the [=URL path serializer=] with |url|, if - |url|'s [=url/path=] is not the empty string and is not [=list/empty=], - or null otherwise. - -
search -
- 1. If |has search| is false: - - 1. null. - - 1. Otherwise: - - 1. The empty string if |url|'s [=url/query=] is null, or |url|'s [=url/query=] otherwise. -
- -1. Return [=success=] with data |parsed|. - -
- -
-To match URL pattern given |url pattern| and |url string|: - -1. Let |url| be the result of [=URL parser|parsing=] |url string|. - -1. If |url pattern|'s protocol is not null and is not equal to |url|'s - [=url/scheme=], return false. - -1. If |url pattern|'s hostname is not null and is not equal to |url|'s - [=url/host=], return false. - -1. If |url pattern|'s port is not null: - - 1. Let |port| be null. - - 1. If |url|'s [=url/scheme=] [=is special=] and |url|'s - [=url/scheme=]'s [=default port=] is not null, and |url|'s [=url/port=] is - null or is equal to [=url/scheme=]'s [=default port=]: - - 1. Set |port| to the empty string. - - 1. Otherwise, if |url|'s [=url/port=], is not null: - - 1. Set |port| to [=serialize an integer=] with |url|'s [=url/port=]. - - 1. If |url pattern|'s port is not equal to |port|, return false. - -1. If |url pattern|'s pathname is not null and is not equal to the result of - running the [=URL path serializer=] with |url|, return false. - -1. If |url pattern|'s search is not null: - - 1. Let |url query| be |url|'s [=url/query=]. - - 1. If |url query| is null, set |url query| to the empty string. - - 1. If |url pattern|'s search is not equal to |url query|, return false. - -1. Return true. +1. Return [=success=] with data |url pattern|.