Skip to content

Commit d0a4f62

Browse files
author
Yves-Marie
committed
Add proper canonicalization of domain names
The current specs only handle host canonicalization for IP addresses and opaque hostnames but if an URL has a special scheme its host should be normalized as a domain name (IDNA processing). Cf. whatwg#220
1 parent 9dae792 commit d0a4f62

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

spec.bs

+19-7
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]:
472472
1. Set |urlPattern|'s [=URL pattern/username component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/username}}"], [=canonicalize a username=], and [=default options=].
473473
1. Set |urlPattern|'s [=URL pattern/password component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/password}}"], [=canonicalize a password=], and [=default options=].
474474
1. If the result running [=hostname pattern is an IPv6 address=] given |processedInit|["{{URLPatternInit/hostname}}"] is true, then set |urlPattern|'s [=URL pattern/hostname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/hostname}}"], [=canonicalize an IPv6 hostname=], and [=hostname options=].
475+
1. Otherwise, if the result of running [=protocol component matches a special scheme=] given |urlPattern|'s [=URL pattern/protocol component=] is true, or |urlPattern|'s [=URL pattern/protocol component=]'s [=component/pattern string=] is "`*`", then set |urlPattern|'s [=URL pattern/hostname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/hostname}}"], [=canonicalize a domain name=], and [=hostname options=].
475476
1. Otherwise, set |urlPattern|'s [=URL pattern/hostname component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/hostname}}"], [=canonicalize a hostname=], and [=hostname options=].
476477
1. Set |urlPattern|'s [=URL pattern/port component=] to the result of [=compiling a component=] given |processedInit|["{{URLPatternInit/port}}"], [=canonicalize a port=], and [=default options=].
477478
1. Let |compileOptions| be a copy of the [=default options=] with the [=options/ignore case=] property set to |options|["{{URLPatternOptions/ignoreCase}}"].
@@ -1729,15 +1730,23 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
17291730
</div>
17301731

17311732
<div algorithm>
1732-
To <dfn>canonicalize a hostname</dfn> given a string |value|:
1733+
To <dfn>canonicalize a hostname</dfn> given a string |value| and optionally a string |protocolValue|:
17331734

17341735
1. If |value| is the empty string, return |value|.
17351736
1. Let |dummyURL| be a new [=URL record=].
1737+
1. If |protocolValue| was given, then set |dummyURL|'s [=url/scheme=] to |protocolValue|.
1738+
<p class="note">We set the [=URL record=]'s [=url/scheme=] in order for the [=basic URL parser=] to recognize and normalize non-opaque hostname values.</p>
17361739
1. Let |parseResult| be the result of running the [=basic URL parser=] given |value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=hostname state=] as <i>[=basic URL parser/state override=]</i>.
17371740
1. If |parseResult| is failure, then throw a {{TypeError}}.
17381741
1. Return |dummyURL|'s [=url/host=], [=host serializer|serialized=], or empty string if it is null.
17391742
</div>
17401743

1744+
<div algorithm>
1745+
To <dfn>canonicalize a domain name</dfn> given a string |value|:
1746+
1747+
1. Return the result of running [=canonicalize a hostname=] given |value| and "`https`".
1748+
</div>
1749+
17411750
<div algorithm>
17421751
To <dfn>canonicalize an IPv6 hostname</dfn> given a string |value|:
17431752

@@ -1869,7 +1878,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
18691878
1. If |init|["{{URLPatternInit/protocol}}"] [=map/exists=], then set |result|["{{URLPatternInit/protocol}}"] to the result of [=process protocol for init=] given |init|["{{URLPatternInit/protocol}}"] and |type|.
18701879
1. If |init|["{{URLPatternInit/username}}"] [=map/exists=], then set |result|["{{URLPatternInit/username}}"] to the result of [=process username for init=] given |init|["{{URLPatternInit/username}}"] and |type|.
18711880
1. If |init|["{{URLPatternInit/password}}"] [=map/exists=], then set |result|["{{URLPatternInit/password}}"] to the result of [=process password for init=] given |init|["{{URLPatternInit/password}}"] and |type|.
1872-
1. If |init|["{{URLPatternInit/hostname}}"] [=map/exists=], then set |result|["{{URLPatternInit/hostname}}"] to the result of [=process hostname for init=] given |init|["{{URLPatternInit/hostname}}"] and |type|.
1881+
1. If |init|["{{URLPatternInit/hostname}}"] [=map/exists=], then set |result|["{{URLPatternInit/hostname}}"] to the result of [=process hostname for init=] given |init|["{{URLPatternInit/hostname}}"], |result|["{{URLPatternInit/protocol}}"], and |type|.
18731882
1. If |init|["{{URLPatternInit/port}}"] [=map/exists=], then set |result|["{{URLPatternInit/port}}"] to the result of [=process port for init=] given |init|["{{URLPatternInit/port}}"], |result|["{{URLPatternInit/protocol}}"], and |type|.
18741883
1. If |init|["{{URLPatternInit/pathname}}"] [=map/exists=]:
18751884
1. Set |result|["{{URLPatternInit/pathname}}"] to |init|["{{URLPatternInit/pathname}}"].
@@ -1935,10 +1944,12 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
19351944
</div>
19361945

19371946
<div algorithm>
1938-
To <dfn>process hostname for init</dfn> given a string |value| and a string |type|:
1947+
To <dfn>process hostname for init</dfn> given a string |hostnameValue|, a string |protocolValue|, and a string |type|:
19391948

1940-
1. If |type| is "`pattern`" then return |value|.
1941-
1. Return the result of running [=canonicalize a hostname=] given |value|.
1949+
1. If |type| is "`pattern`" then return |hostnameValue|.
1950+
1. If |protocolValue| is a [=special scheme=] or the empty string, then return the result of running [=canonicalize a domain name=] given |hostnameValue|.
1951+
<p class="note">If the |protocolValue| is the empty string then no value was provided for {{URLPatternInit/protocol}} in the constructor dictionary. Normally we do not special case empty string dictionary values, but in this case we treat it as a [=special scheme=] in order to default to the most common hostname canonicalization.</p>
1952+
1. Return the result of running [=canonicalize a hostname=] given |hostnameValue|.
19421953
</div>
19431954

19441955
<div algorithm>
@@ -2113,8 +2124,9 @@ Ralph Chelala,
21132124
Sangwhan Moon,
21142125
Sayan Pal,
21152126
Victor Costan,
2116-
Yoshisato Yanagisawa, and
2117-
Youenn Fablet
2127+
Yoshisato Yanagisawa,
2128+
Youenn Fablet, and
2129+
Yves-Marie K. Rinquin
21182130
for their contributors to this specification.
21192131

21202132
Special thanks to Blake Embrey and the other [pillarjs/path-to-regexp](https://github.com/pillarjs/path-to-regexp) [contributors](https://github.com/pillarjs/path-to-regexp/graphs/contributors) for building an excellent open source library that so many have found useful.

0 commit comments

Comments
 (0)