Skip to content
Permalink
Browse files

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.
  • Loading branch information...
annevk committed Feb 8, 2017
1 parent 6688baa commit cf616f9d3fca44bd5329e992519a4236a39b0cb7
Showing with 45 additions and 21 deletions.
  1. +45 −21 url.bs
66 url.bs
@@ -924,6 +924,10 @@ used by HTML. [[HTML]]
<a for=url>username</a> or <a for=url>password</a> is not the empty string.
<!-- also used by Fetch -->

<p>A <a for=/>URL</a> <dfn export>cannot have a username/password/port</dfn> if its
<a for=url>host</a> is null or the empty string, its <a for=url>cannot-be-a-base-URL flag</a> is
set, or its <a for=url>scheme</a> is "<code>file</code>".

<p>A <a for=/>URL</a> can be designated as <dfn id=concept-base-url>base URL</dfn>.

<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
<dt><dfn>hostname state</dfn>
<dd>
<ol>
<li><p>If <var>state override</var> is given and <var>url</var>'s <a for=url>scheme</a> is
"<code>file</code>", then decrease <var>pointer</var> by one and set <var>state</var> to
<a>file host state</a>.

<li>
<p>If <a>c</a> is "<code>:</code>" and the
<var>[] flag</var> is unset, run these substeps:
<p>Otherwise, if <a>c</a> is "<code>:</code>" and the <var>[] flag</var> is unset, then:

<ol>
<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
<!-- http://? -> failure
test://? -> test://? -->

<li><p>Otherwise, if <var>state override</var> is given, <var>buffer</var> is the empty
string, and either <var>url</var> <a>includes credentials</a> or <var>url</var>'s
<a for=url>port</a> is non-null, <a>syntax violation</a>, return.

<li><p>Let <var>host</var> be the result of <a lt="URL-host parser">URL-host parsing</a>
<var>buffer</var> with <var>url</var> <a>is special</a>.

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

<ol>
<li>
<p>If <var>buffer</var> is a <a>Windows drive letter</a>, <a>syntax violation</a>,
set <var>state</var> to <a>path state</a>.

<p class=note>This is a (platform-independent) Windows drive letter quirk.
<var>buffer</var> is not reset here and instead used in the
<p>If <var>state override</var> is not given and <var>buffer</var> is a
<a>Windows drive letter</a>, <a>syntax violation</a>, set <var>state</var> to
<a>path state</a>.

<li><p>Otherwise, if <var>buffer</var> is the empty string, set
<var>state</var> to <a>path start state</a>.
<p class=note>This is a (platform-independent) Windows drive letter quirk. <var>buffer</var>
is not reset here and instead used in the <a>path state</a>.

<li>
<p>Otherwise, if <var>buffer</var> is the empty string, then:

<ol>
<li><p>If <var>state override</var> is given and <var>url</var>
<a>includes credentials</a>, <a>syntax violation</a>, return.

<li><p>Set <var>url</var>'s <a for=url>host</a> to the empty string.

<li><p>If <var>state override</var> is given, then return.

<li><p>Set <var>state</var> to <a>path start state</a>.
</ol>

<li>
<p>Otherwise, run these steps:

<ol>
<li><p>Let <var>host</var> be the result of
<a lt='host parser'>host parsing</a>
<li><p>Let <var>host</var> be the result of <a lt="host parser">host parsing</a>
<var>buffer</var>.

<li><p>If <var>host</var> is failure, return failure.
<li><p>If <var>host</var> is failure, then return failure.

<li><p>If <var>host</var> is "<code title>localhost</code>", then set <var>host</var> to
the empty string.

<li><p>Set <var>url</var>'s <a for=url>host</a> to <var>host</var>.

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

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

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

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

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

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

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

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

0 comments on commit cf616f9

Please sign in to comment.
You can’t perform that action at this time.