From 9aa8046369c8624f201fb69a0809fe169a3f4ebd Mon Sep 17 00:00:00 2001 From: Yoshisato Yanagisawa Date: Tue, 27 Feb 2024 23:20:37 +0000 Subject: [PATCH 1/6] Make test() and exec() accept URL The original specification did not explicitly accept a URL object as an input, and expected implicit conversion from the URL object to the URLPatternInit object for matching. This change make the URL object accepted as an input explicitly. This is a step to fix https://github.com/whatwg/urlpattern/issues/218. --- spec.bs | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/spec.bs b/spec.bs index a567e5a..99fbd1b 100644 --- a/spec.bs +++ b/spec.bs @@ -11,6 +11,7 @@ Markup Shorthands: markdown yes
@@ -21,6 +22,15 @@ spec: ECMASCRIPT; urlPrefix: https://tc39.es/ecma262/
 spec: URL; urlPrefix: https://url.spec.whatwg.org/
   type: dfn
     text: serialize an integer; url: #serialize-an-integer
+    text: url; url: #concept-url
+    text: scheme; for: url; url: #concept-url-scheme
+    text: username; for: url; url: #concept-url-username
+    text: password; for: url; url: #concept-url-password
+    text: host; for: url; url: #concept-url-host
+    text: port; for: url; url: #concept-url-port
+    text: path; for: url; url: #concept-url-path
+    text: query; for: url; url: #concept-url-query
+    text: fragment; for: url; url: #concept-url-fragment
 

URL patterns

@@ -171,15 +181,16 @@ It can be constructed using a string for each component, or from a shorthand str typedef (USVString or URLPatternInit) URLPatternInput; +typedef (URLPatternInput or URL) URLPatternMatchInput; [Exposed=(Window,Worker)] interface URLPattern { constructor(URLPatternInput input, USVString baseURL, optional URLPatternOptions options = {}); constructor(optional URLPatternInput input = {}, optional URLPatternOptions options = {}); - boolean test(optional URLPatternInput input = {}, optional USVString baseURL); + boolean test(optional URLPatternMatchInput input = {}, optional USVString baseURL); - URLPatternResult? exec(optional URLPatternInput input = {}, optional USVString baseURL); + URLPatternResult? exec(optional URLPatternMatchInput input = {}, optional USVString baseURL); readonly attribute USVString protocol; readonly attribute USVString username; @@ -468,7 +479,7 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: </div> <div algorithm> - To perform a <dfn export for="URL pattern">match</dfn> given a [=URL pattern=] |urlPattern|, a {{URLPatternInput}} |input|, and an optional string |baseURLString|: + To perform a <dfn export for="URL pattern">match</dfn> given a [=URL pattern=] |urlPattern|, a {{URLPatternMatchInput}} |input|, and an optional string |baseURLString|: 1. Let |protocol| be the empty string. 1. Let |username| be the empty string. @@ -480,7 +491,17 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: 1. Let |hash| be the empty string. 1. Let |inputs| be an empty [=list=]. 1. [=list/Append=] |input| to |inputs|. - 1. If |input| is a {{URLPatternInit}} then: + 1. If |input| is a {{URL}} then: + 1. Let |associatedUrl| be |input|'s associated [=URL=]. + 1. Set |protocol| to |associatedUrl|'s [=url/scheme=]. + 1. Set |username| to |associatedUrl|'s [=url/username=]. + 1. Set |password| to |associatedUrl|'s [=url/password=]. + 1. Set |hostname| to |associatedUrl|'s [=url/host=]. + 1. Set |port| to |associatedUrl|'s [=url/port=]. + 1. Set |pathname| to |associatedUrl|'s [=url/path=]. + 1. Set |search| to |associatedUrl|'s [=url/query=]. + 1. Set |hash| to |associatedUrl|'s [=url/fragment=]. + 1. Else if |input| is a {{URLPatternInit}} then: 1. If |baseURLString| was given, throw a {{TypeError}}. 1. Let |applyResult| be the result of [=process a URLPatternInit=] given |input|, "url", |protocol|, |username|, |password|, |hostname|, |port|, |pathname|, |search|, and |hash|. If this throws an exception, catch it, and return null. 1. Set |protocol| to |applyResult|["{{URLPatternInit/protocol}}"]. @@ -491,7 +512,8 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: 1. Set |pathname| to |applyResult|["{{URLPatternInit/pathname}}"]. 1. Set |search| to |applyResult|["{{URLPatternInit/search}}"]. 1. Set |hash| to |applyResult|["{{URLPatternInit/hash}}"]. - 1. Otherwise: + 1. Else: + 1. [=Assert=]: |input| is a {{USVString}}. 1. Let |baseURL| be null. 1. If |baseURLString| was given, then: 1. Set |baseURL| to the result of [=URL parser|parsing=] |baseURLString|. From 6983a8c038510a758e99d851cf068b06882bee5a Mon Sep 17 00:00:00 2001 From: Yoshisato Yanagisawa <yyanagisawa@chromium.org> Date: Wed, 28 Feb 2024 06:28:46 +0000 Subject: [PATCH 2/6] Addressed comments. - Not chagne `exec()` or `test()` arguments. - make the match algorithm accept [=/url=]. - By merging existing steps, omitted the explicit declaration of anchors. --- spec.bs | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/spec.bs b/spec.bs index 99fbd1b..b04b7c6 100644 --- a/spec.bs +++ b/spec.bs @@ -11,7 +11,6 @@ Markup Shorthands: markdown yes <pre class="link-defaults"> spec:infra; type:dfn; text:list spec:webidl; type:dfn; text:record -spec:url; type:interface; text:URL </pre> <pre class="anchors"> @@ -22,15 +21,6 @@ spec: ECMASCRIPT; urlPrefix: https://tc39.es/ecma262/ spec: URL; urlPrefix: https://url.spec.whatwg.org/ type: dfn text: serialize an integer; url: #serialize-an-integer - text: url; url: #concept-url - text: scheme; for: url; url: #concept-url-scheme - text: username; for: url; url: #concept-url-username - text: password; for: url; url: #concept-url-password - text: host; for: url; url: #concept-url-host - text: port; for: url; url: #concept-url-port - text: path; for: url; url: #concept-url-path - text: query; for: url; url: #concept-url-query - text: fragment; for: url; url: #concept-url-fragment </pre> <h2 id=urlpatterns>URL patterns</h2> @@ -181,16 +171,15 @@ It can be constructed using a string for each component, or from a shorthand str <xmp class="idl"> typedef (USVString or URLPatternInit) URLPatternInput; -typedef (URLPatternInput or URL) URLPatternMatchInput; [Exposed=(Window,Worker)] interface URLPattern { constructor(URLPatternInput input, USVString baseURL, optional URLPatternOptions options = {}); constructor(optional URLPatternInput input = {}, optional URLPatternOptions options = {}); - boolean test(optional URLPatternMatchInput input = {}, optional USVString baseURL); + boolean test(optional URLPatternInput input = {}, optional USVString baseURL); - URLPatternResult? exec(optional URLPatternMatchInput input = {}, optional USVString baseURL); + URLPatternResult? exec(optional URLPatternInput input = {}, optional USVString baseURL); readonly attribute USVString protocol; readonly attribute USVString username; @@ -479,7 +468,7 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: </div> <div algorithm> - To perform a <dfn export for="URL pattern">match</dfn> given a [=URL pattern=] |urlPattern|, a {{URLPatternMatchInput}} |input|, and an optional string |baseURLString|: + To perform a <dfn export for="URL pattern">match</dfn> given a [=URL pattern=] |urlPattern|, a {{URLPatternInput}} or [=/url=] |input|, and an optional string |baseURLString|: 1. Let |protocol| be the empty string. 1. Let |username| be the empty string. @@ -491,17 +480,7 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: 1. Let |hash| be the empty string. 1. Let |inputs| be an empty [=list=]. 1. [=list/Append=] |input| to |inputs|. - 1. If |input| is a {{URL}} then: - 1. Let |associatedUrl| be |input|'s associated [=URL=]. - 1. Set |protocol| to |associatedUrl|'s [=url/scheme=]. - 1. Set |username| to |associatedUrl|'s [=url/username=]. - 1. Set |password| to |associatedUrl|'s [=url/password=]. - 1. Set |hostname| to |associatedUrl|'s [=url/host=]. - 1. Set |port| to |associatedUrl|'s [=url/port=]. - 1. Set |pathname| to |associatedUrl|'s [=url/path=]. - 1. Set |search| to |associatedUrl|'s [=url/query=]. - 1. Set |hash| to |associatedUrl|'s [=url/fragment=]. - 1. Else if |input| is a {{URLPatternInit}} then: + 1. If |input| is a {{URLPatternInit}} then: 1. If |baseURLString| was given, throw a {{TypeError}}. 1. Let |applyResult| be the result of [=process a URLPatternInit=] given |input|, "url", |protocol|, |username|, |password|, |hostname|, |port|, |pathname|, |search|, and |hash|. If this throws an exception, catch it, and return null. 1. Set |protocol| to |applyResult|["{{URLPatternInit/protocol}}"]. @@ -512,15 +491,17 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: 1. Set |pathname| to |applyResult|["{{URLPatternInit/pathname}}"]. 1. Set |search| to |applyResult|["{{URLPatternInit/search}}"]. 1. Set |hash| to |applyResult|["{{URLPatternInit/hash}}"]. - 1. Else: - 1. [=Assert=]: |input| is a {{USVString}}. - 1. Let |baseURL| be null. - 1. If |baseURLString| was given, then: - 1. Set |baseURL| to the result of [=URL parser|parsing=] |baseURLString|. - 1. If |baseURL| is failure, return null. - 1. [=list/Append=] |baseURLString| to |inputs|. - 1. Let |url| be the result of [=URL parser|parsing=] |input| given |baseURL|. - 1. If |url| is failure, return null. + 1. Otherwise: + 1. Let |url| be |input|. + 1. If |input| is a {{USVString}}: + 1. Let |baseURL| be null. + 1. If |baseURLString| was given, then: + 1. Set |baseURL| to the result of [=URL parser|parsing=] |baseURLString|. + 1. If |baseURL| is failure, return null. + 1. [=list/Append=] |baseURLString| to |inputs|. + 1. Let |url| be the result of [=URL parser|parsing=] |input| given |baseURL|. + 1. If |url| is failure, return null. + 1. [=Assert=]: |url| is [=/url=] 1. Set |protocol| to |url|'s [=url/scheme=]. 1. Set |username| to |url|'s [=url/username=]. 1. Set |password| to |url|'s [=url/password=]. From 1e9b1902e5824fd20c10518553fcdda46ed34c8c Mon Sep 17 00:00:00 2001 From: Yoshisato Yanagisawa <yyanagisawa@chromium.org> Date: Wed, 28 Feb 2024 06:31:45 +0000 Subject: [PATCH 3/6] Minor fix on Let and Set. --- spec.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.bs b/spec.bs index b04b7c6..78b34c4 100644 --- a/spec.bs +++ b/spec.bs @@ -499,7 +499,7 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: 1. Set |baseURL| to the result of [=URL parser|parsing=] |baseURLString|. 1. If |baseURL| is failure, return null. 1. [=list/Append=] |baseURLString| to |inputs|. - 1. Let |url| be the result of [=URL parser|parsing=] |input| given |baseURL|. + 1. Set |url| be the result of [=URL parser|parsing=] |input| given |baseURL|. 1. If |url| is failure, return null. 1. [=Assert=]: |url| is [=/url=] 1. Set |protocol| to |url|'s [=url/scheme=]. From e2631be6c7c409bd802f7d4d162f9e65b2ec9fbf Mon Sep 17 00:00:00 2001 From: Yoshisato Yanagisawa <yoshisato.yanagisawa@gmail.com> Date: Wed, 28 Feb 2024 19:34:19 +0900 Subject: [PATCH 4/6] Update spec.bs Co-authored-by: Domenic Denicola <d@domenic.me> --- spec.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.bs b/spec.bs index 78b34c4..fe19986 100644 --- a/spec.bs +++ b/spec.bs @@ -501,7 +501,7 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: 1. [=list/Append=] |baseURLString| to |inputs|. 1. Set |url| be the result of [=URL parser|parsing=] |input| given |baseURL|. 1. If |url| is failure, return null. - 1. [=Assert=]: |url| is [=/url=] + 1. [=Assert=]: |url| is a [=/URL=]. 1. Set |protocol| to |url|'s [=url/scheme=]. 1. Set |username| to |url|'s [=url/username=]. 1. Set |password| to |url|'s [=url/password=]. From 3847bc665b9cd996b99444b6301309d5738442ce Mon Sep 17 00:00:00 2001 From: Yoshisato Yanagisawa <yyanagisawa@chromium.org> Date: Wed, 28 Feb 2024 10:35:26 +0000 Subject: [PATCH 5/6] Applied the fix. --- spec.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.bs b/spec.bs index fe19986..c8e2ed6 100644 --- a/spec.bs +++ b/spec.bs @@ -499,7 +499,7 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: 1. Set |baseURL| to the result of [=URL parser|parsing=] |baseURLString|. 1. If |baseURL| is failure, return null. 1. [=list/Append=] |baseURLString| to |inputs|. - 1. Set |url| be the result of [=URL parser|parsing=] |input| given |baseURL|. + 1. Set |url| to the result of [=URL parser|parsing=] |input| given |baseURL|. 1. If |url| is failure, return null. 1. [=Assert=]: |url| is a [=/URL=]. 1. Set |protocol| to |url|'s [=url/scheme=]. From 483bccb83a3807ea1e2e87015ba5f12af9137e13 Mon Sep 17 00:00:00 2001 From: Yoshisato Yanagisawa <yoshisato.yanagisawa@gmail.com> Date: Thu, 29 Feb 2024 08:38:02 +0900 Subject: [PATCH 6/6] Update spec.bs Co-authored-by: Jeremy Roman <jeremy@jeremyroman.com> --- spec.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.bs b/spec.bs index c8e2ed6..caab756 100644 --- a/spec.bs +++ b/spec.bs @@ -468,7 +468,7 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]: </div> <div algorithm> - To perform a <dfn export for="URL pattern">match</dfn> given a [=URL pattern=] |urlPattern|, a {{URLPatternInput}} or [=/url=] |input|, and an optional string |baseURLString|: + To perform a <dfn export for="URL pattern">match</dfn> given a [=URL pattern=] |urlPattern|, a {{URLPatternInput}} or [=/URL=] |input|, and an optional string |baseURLString|: 1. Let |protocol| be the empty string. 1. Let |username| be the empty string.