Skip to content

Commit cf616f9

Browse files
authored
Cleanup API for file and non-special URLs
This: * Stops the username/password/port APIs from functioning when host is the empty string. * Makes the host/hostname APIs work better with file URLs and adjusts the file host state accordingly. * Make setting host/hostname to the empty string impossible when they have a username/password/port. * Fixes #97.
1 parent 6688baa commit cf616f9

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

url.bs

+45-21
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,10 @@ used by HTML. [[HTML]]
924924
<a for=url>username</a> or <a for=url>password</a> is not the empty string.
925925
<!-- also used by Fetch -->
926926

927+
<p>A <a for=/>URL</a> <dfn export>cannot have a username/password/port</dfn> if its
928+
<a for=url>host</a> is null or the empty string, its <a for=url>cannot-be-a-base-URL flag</a> is
929+
set, or its <a for=url>scheme</a> is "<code>file</code>".
930+
927931
<p>A <a for=/>URL</a> can be designated as <dfn id=concept-base-url>base URL</dfn>.
928932

929933
<p class="note no-backref">A <a>base URL</a> is useful for the <a>URL parser</a> when the
@@ -1636,9 +1640,12 @@ string <var>input</var>, optionally with a <a>base URL</a> <var>base</var>, opti
16361640
<dt><dfn>hostname state</dfn>
16371641
<dd>
16381642
<ol>
1643+
<li><p>If <var>state override</var> is given and <var>url</var>'s <a for=url>scheme</a> is
1644+
"<code>file</code>", then decrease <var>pointer</var> by one and set <var>state</var> to
1645+
<a>file host state</a>.
1646+
16391647
<li>
1640-
<p>If <a>c</a> is "<code>:</code>" and the
1641-
<var>[] flag</var> is unset, run these substeps:
1648+
<p>Otherwise, if <a>c</a> is "<code>:</code>" and the <var>[] flag</var> is unset, then:
16421649

16431650
<ol>
16441651
<li><p>If <var>buffer</var> is the empty string, <a>syntax violation</a>, return failure.
@@ -1674,6 +1681,10 @@ string <var>input</var>, optionally with a <a>base URL</a> <var>base</var>, opti
16741681
<!-- http://? -> failure
16751682
test://? -> test://? -->
16761683

1684+
<li><p>Otherwise, if <var>state override</var> is given, <var>buffer</var> is the empty
1685+
string, and either <var>url</var> <a>includes credentials</a> or <var>url</var>'s
1686+
<a for=url>port</a> is non-null, <a>syntax violation</a>, return.
1687+
16771688
<li><p>Let <var>host</var> be the result of <a lt="URL-host parser">URL-host parsing</a>
16781689
<var>buffer</var> with <var>url</var> <a>is special</a>.
16791690

@@ -1854,28 +1865,42 @@ string <var>input</var>, optionally with a <a>base URL</a> <var>base</var>, opti
18541865

18551866
<ol>
18561867
<li>
1857-
<p>If <var>buffer</var> is a <a>Windows drive letter</a>, <a>syntax violation</a>,
1858-
set <var>state</var> to <a>path state</a>.
1859-
1860-
<p class=note>This is a (platform-independent) Windows drive letter quirk.
1861-
<var>buffer</var> is not reset here and instead used in the
1868+
<p>If <var>state override</var> is not given and <var>buffer</var> is a
1869+
<a>Windows drive letter</a>, <a>syntax violation</a>, set <var>state</var> to
18621870
<a>path state</a>.
18631871

1864-
<li><p>Otherwise, if <var>buffer</var> is the empty string, set
1865-
<var>state</var> to <a>path start state</a>.
1872+
<p class=note>This is a (platform-independent) Windows drive letter quirk. <var>buffer</var>
1873+
is not reset here and instead used in the <a>path state</a>.
1874+
1875+
<li>
1876+
<p>Otherwise, if <var>buffer</var> is the empty string, then:
1877+
1878+
<ol>
1879+
<li><p>If <var>state override</var> is given and <var>url</var>
1880+
<a>includes credentials</a>, <a>syntax violation</a>, return.
1881+
1882+
<li><p>Set <var>url</var>'s <a for=url>host</a> to the empty string.
1883+
1884+
<li><p>If <var>state override</var> is given, then return.
1885+
1886+
<li><p>Set <var>state</var> to <a>path start state</a>.
1887+
</ol>
18661888

18671889
<li>
18681890
<p>Otherwise, run these steps:
18691891

18701892
<ol>
1871-
<li><p>Let <var>host</var> be the result of
1872-
<a lt='host parser'>host parsing</a>
1893+
<li><p>Let <var>host</var> be the result of <a lt="host parser">host parsing</a>
18731894
<var>buffer</var>.
18741895

1875-
<li><p>If <var>host</var> is failure, return failure.
1896+
<li><p>If <var>host</var> is failure, then return failure.
1897+
1898+
<li><p>If <var>host</var> is "<code title>localhost</code>", then set <var>host</var> to
1899+
the empty string.
1900+
1901+
<li><p>Set <var>url</var>'s <a for=url>host</a> to <var>host</var>.
18761902

1877-
<li><p>If <var>host</var> is not "<code title>localhost</code>", set
1878-
<var>url</var>'s <a for=url>host</a> to <var>host</var>.
1903+
<li><p>If <var>state override</var> is given, then return.
18791904

18801905
<li><p>Set <var>buffer</var> to the empty string and <var>state</var> to
18811906
<a>path start state</a>.
@@ -2620,8 +2645,8 @@ compatibility with HTML's <code>MessageEvent</code> feature. [[!HTML]]
26202645
<p>The <code><a attribute for=URL>username</a></code> attribute's setter must run these steps:
26212646

26222647
<ol>
2623-
<li><p>If <a>context object</a>'s <a for=URL>url</a>'s <a for=url>host</a> is null, or its
2624-
<a for=url>cannot-be-a-base-URL flag</a> is set, terminate these steps.
2648+
<li><p>If <a>context object</a>'s <a for=URL>url</a> <a>cannot have a username/password/port</a>,
2649+
then return.
26252650

26262651
<li><p><a for=url>Set the username</a> given <a>context object</a>'s <a for=URL>url</a> and the
26272652
given value.
@@ -2633,8 +2658,8 @@ compatibility with HTML's <code>MessageEvent</code> feature. [[!HTML]]
26332658
<p>The <code><a attribute for=URL>password</a></code> attribute's setter must run these steps:
26342659

26352660
<ol>
2636-
<li><p>If <a>context object</a>'s <a for=URL>url</a>'s <a for=url>host</a> is null, or its
2637-
<a for=url>cannot-be-a-base-URL flag</a> is set, terminate these steps.
2661+
<li><p>If <a>context object</a>'s <a for=URL>url</a> <a>cannot have a username/password/port</a>,
2662+
then return.
26382663

26392664
<li><p><a for=url>Set the password</a> given <a>context object</a>'s <a for=URL>url</a> and the
26402665
given value.
@@ -2704,9 +2729,8 @@ the setter to always "reset" both.
27042729
<p>The <code><a attribute for=URL>port</a></code> attribute's setter must run these steps:
27052730

27062731
<ol>
2707-
<li><p>If <a>context object</a>'s <a for=URL>url</a>'s <a for=url>host</a> is null, its
2708-
<a for=url>cannot-be-a-base-URL flag</a> is set, or its <a for=url>scheme</a> is
2709-
"<code>file</code>", terminate these steps.
2732+
<li><p>If <a>context object</a>'s <a for=URL>url</a> <a>cannot have a username/password/port</a>,
2733+
then return.
27102734

27112735
<li><p>If the given value is the empty string, then set <a for=URL>url</a>'s <a for=url>port</a> to
27122736
null.</p></li>

0 commit comments

Comments
 (0)