Skip to content

Commit 46c30fd

Browse files
authored
Make dummyURL from the basic URL parser with a special scheme
Per discussion in #252, this creates a dummy URL from the basic URL parser rather than using URL records directly to canonicalize components. Also this specifies a special scheme as a default scheme.
1 parent 5c979a3 commit 46c30fd

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

spec.bs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]:
599599
1. Return |result|.
600600
</div>
601601

602+
<div algorithm>
603+
To <dfn export for="URL pattern">create a dummy URL</dfn>:
604+
605+
1. Let |dummyInput| be "`https://dummy.invalid/`".
606+
1. Return the result of running the [=basic URL parser=] on |dummyInput|.
607+
</div>
608+
602609
The <dfn>default options</dfn> is an [=options=] [=struct=] with [=options/delimiter code point=] set to the empty string and [=options/prefix code point=] set to the empty string.
603610

604611
The <dfn>hostname options</dfn> is an [=options=] [=struct=] with [=options/delimiter code point=] set "`.`" and [=options/prefix code point=] set to the empty string.
@@ -1704,18 +1711,17 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
17041711
To <dfn>canonicalize a protocol</dfn> given a string |value|:
17051712

17061713
1. If |value| is the empty string, return |value|.
1707-
1. Let |dummyURL| be a new [=URL record=].
1708-
1. Let |parseResult| be the result of running the [=basic URL parser=] given |value| followed by "`://dummy.test`", with |dummyURL| as <i>[=basic URL parser/url=]</i>.
1714+
1. Let |parseResult| be the result of running the [=basic URL parser=] given |value| followed by "`://dummy.invalid/`".
17091715
<p class="note">Note, [=basic URL parser/state override=] is not used here because it enforces restrictions that are only appropriate for the {{URL/protocol}} setter. Instead we use the protocol to parse a dummy URL using the normal parsing entry point.</p>
17101716
1. If |parseResult| is failure, then throw a {{TypeError}}.
1711-
1. Return |dummyURL|'s [=url/scheme=].
1717+
1. Return |parseResult|'s [=url/scheme=].
17121718
</div>
17131719

17141720
<div algorithm>
17151721
To <dfn>canonicalize a username</dfn> given a string |value|:
17161722

17171723
1. If |value| is the empty string, return |value|.
1718-
1. Let |dummyURL| be a new [=URL record=].
1724+
1. Let |dummyURL| be the result of [=creating a dummy URL=].
17191725
1. [=Set the username=] given |dummyURL| and |value|.
17201726
1. Return |dummyURL|'s [=url/username=].
17211727
</div>
@@ -1724,7 +1730,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
17241730
To <dfn>canonicalize a password</dfn> given a string |value|:
17251731

17261732
1. If |value| is the empty string, return |value|.
1727-
1. Let |dummyURL| be a new [=URL record=].
1733+
1. Let |dummyURL| be the result of [=creating a dummy URL=].
17281734
1. [=Set the password=] given |dummyURL| and |value|.
17291735
1. Return |dummyURL|'s [=url/password=].
17301736
</div>
@@ -1733,7 +1739,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
17331739
To <dfn>canonicalize a hostname</dfn> given a string |value|:
17341740

17351741
1. If |value| is the empty string, return |value|.
1736-
1. Let |dummyURL| be a new [=URL record=].
1742+
1. Let |dummyURL| be the result of [=creating a dummy URL=].
17371743
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>.
17381744
1. If |parseResult| is failure, then throw a {{TypeError}}.
17391745
1. Return |dummyURL|'s [=url/host=], [=host serializer|serialized=], or empty string if it is null.
@@ -1760,7 +1766,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
17601766
To <dfn>canonicalize a port</dfn> given a string |portValue| and optionally a string |protocolValue|:
17611767

17621768
1. If |portValue| is the empty string, return |portValue|.
1763-
1. Let |dummyURL| be a new [=URL record=].
1769+
1. Let |dummyURL| be the result of [=creating a dummy URL=].
17641770
1. If |protocolValue| was given, then set |dummyURL|'s [=url/scheme=] to |protocolValue|.
17651771
<p class="note">Note, we set the [=URL record=]'s [=url/scheme=] in order for the [=basic URL parser=] to recognize and normalize default port values.</p>
17661772
1. Let |parseResult| be the result of running [=basic URL parser=] given |portValue| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=port state=] as <i>[=basic URL parser/state override=]</i>.
@@ -1779,7 +1785,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
17791785
<p>Note, implementations are free to simply disable slash prepending in their URL parsing code instead of paying the performance penalty of inserting and removing characters in this algorithm.
17801786
</div>
17811787
1. Append |value| to the end of |modified value|.
1782-
1. Let |dummyURL| be a new [=URL record=].
1788+
1. Let |dummyURL| be the result of [=creating a dummy URL=].
17831789
1. Run [=basic URL parser=] given |modified value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=path start state=] as <i>[=basic URL parser/state override=]</i>.
17841790
1. Let |result| be the result of [=URL path serializing=] |dummyURL|.
17851791
1. If |leading slash| is false, then set |result| to the [=code point substring to the end of the string|code point substring=] from 2 to the end of the string within |result|.
@@ -1790,7 +1796,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
17901796
To <dfn>canonicalize an opaque pathname</dfn> given a string |value|:
17911797

17921798
1. If |value| is the empty string, return |value|.
1793-
1. Let |dummyURL| be a new [=URL record=].
1799+
1. Let |dummyURL| be the result of [=creating a dummy URL=].
17941800
1. Set |dummyURL|'s [=url/path=] to the empty string.
17951801
1. Let |parseResult| be the result of running [=basic URL parser|URL parsing=] given |value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=basic URL parser/opaque path state=] as <i>[=basic URL parser/state override=]</i>.
17961802
1. If |parseResult| is failure, then throw a {{TypeError}}.
@@ -1801,7 +1807,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
18011807
To <dfn>canonicalize a search</dfn> given a string |value|:
18021808

18031809
1. If |value| is the empty string, return |value|.
1804-
1. Let |dummyURL| be a new [=URL record=].
1810+
1. Let |dummyURL| be the result of [=creating a dummy URL=].
18051811
1. Set |dummyURL|'s [=url/query=] to the empty string.
18061812
1. Run [=basic URL parser=] given |value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=query state=] as <i>[=basic URL parser/state override=]</i>.
18071813
1. Return |dummyURL|'s [=url/query=].
@@ -1811,7 +1817,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
18111817
To <dfn>canonicalize a hash</dfn> given a string |value|:
18121818

18131819
1. If |value| is the empty string, return |value|.
1814-
1. Let |dummyURL| be a new [=URL record=].
1820+
1. Let |dummyURL| be the result of [=creating a dummy URL=].
18151821
1. Set |dummyURL|'s [=url/fragment=] to the empty string.
18161822
1. Run [=basic URL parser=] given |value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=fragment state=] as <i>[=basic URL parser/state override=]</i>.
18171823
1. Return |dummyURL|'s [=url/fragment=].

0 commit comments

Comments
 (0)