You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: spec.bs
+17-11Lines changed: 17 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -599,6 +599,13 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]:
599
599
1. Return |result|.
600
600
</div>
601
601
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
+
602
609
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.
603
610
604
611
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
1704
1711
To <dfn>canonicalize a protocol</dfn> given a string |value|:
1705
1712
1706
1713
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/`".
1709
1715
<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>
1710
1716
1. If |parseResult| is failure, then throw a {{TypeError}}.
1711
-
1. Return |dummyURL|'s [=url/scheme=].
1717
+
1. Return |parseResult|'s [=url/scheme=].
1712
1718
</div>
1713
1719
1714
1720
<div algorithm>
1715
1721
To <dfn>canonicalize a username</dfn> given a string |value|:
1716
1722
1717
1723
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=].
1719
1725
1. [=Set the username=] given |dummyURL| and |value|.
1720
1726
1. Return |dummyURL|'s [=url/username=].
1721
1727
</div>
@@ -1724,7 +1730,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
1724
1730
To <dfn>canonicalize a password</dfn> given a string |value|:
1725
1731
1726
1732
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=].
1728
1734
1. [=Set the password=] given |dummyURL| and |value|.
1729
1735
1. Return |dummyURL|'s [=url/password=].
1730
1736
</div>
@@ -1733,7 +1739,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
1733
1739
To <dfn>canonicalize a hostname</dfn> given a string |value|:
1734
1740
1735
1741
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=].
1737
1743
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>.
1738
1744
1. If |parseResult| is failure, then throw a {{TypeError}}.
1739
1745
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
1760
1766
To <dfn>canonicalize a port</dfn> given a string |portValue| and optionally a string |protocolValue|:
1761
1767
1762
1768
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=].
1764
1770
1. If |protocolValue| was given, then set |dummyURL|'s [=url/scheme=] to |protocolValue|.
1765
1771
<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>
1766
1772
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
1779
1785
<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.
1780
1786
</div>
1781
1787
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=].
1783
1789
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>.
1784
1790
1. Let |result| be the result of [=URL path serializing=] |dummyURL|.
1785
1791
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
1790
1796
To <dfn>canonicalize an opaque pathname</dfn> given a string |value|:
1791
1797
1792
1798
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=].
1794
1800
1. Set |dummyURL|'s [=url/path=] to the empty string.
1795
1801
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>.
1796
1802
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
1801
1807
To <dfn>canonicalize a search</dfn> given a string |value|:
1802
1808
1803
1809
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=].
1805
1811
1. Set |dummyURL|'s [=url/query=] to the empty string.
1806
1812
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>.
1807
1813
1. Return |dummyURL|'s [=url/query=].
@@ -1811,7 +1817,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
1811
1817
To <dfn>canonicalize a hash</dfn> given a string |value|:
1812
1818
1813
1819
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=].
1815
1821
1. Set |dummyURL|'s [=url/fragment=] to the empty string.
1816
1822
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>.
0 commit comments