Skip to content

Commit

Permalink
Change path parsing for non-special URLs
Browse files Browse the repository at this point in the history
This allows paths to be empty for non-special URLs and also takes that
into account when serializing.

Tests: web-platform-tests/wpt#4586.

Fixes #212.
  • Loading branch information
annevk committed Jan 21, 2017
1 parent 960f607 commit 5e6d4e5
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions url.bs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@ null or a 16-bit unsigned integer that identifies a networking port. It is initi
zero or more <a>ASCII string</a> holding data, usually identifying a location in
hierarchical form. It is initially the empty list.

<p class="note no-backref">A <a lt="is special">special</a> <a for=/>URL</a> always has a
<a for=list lt="is empty">non-empty</a> <a for=url>path</a>.

<p>A <a for=/>URL</a>'s <dfn export for=url id=concept-url-query>query</dfn> is either
null or an <a>ASCII string</a> holding data. It is initially null.

Expand Down Expand Up @@ -1466,15 +1469,18 @@ string <var>input</var>, optionally with a <a>base URL</a> <var>base</var>, opti
<dd>
<ol>
<li>
<p>If either <a>c</a> is "<code>/</code>", or <var>url</var> <a>is special</a> and
<a>c</a> is "<code>\</code>", run these substeps:
<p>If <var>url</var> <a>is special</a> and <a>c</a> is "<code>/</code>" or "<code>\</code>",
then:

<ol>
<li><p>If <a>c</a> is "<code>\</code>", <a>syntax violation</a>.

<li><p>Set <var>state</var> to <a>special authority ignore slashes state</a>.
</ol>

<li><p>Otherwise, if <a>c</a> is "<code>/</code>", then set <var>state</var> to
<a>authority state</a>.

<li><p>Otherwise, set
<var>url</var>'s <a for=url>username</a> to
<var>base</var>'s <a for=url>username</a>,
Expand Down Expand Up @@ -1823,12 +1829,27 @@ string <var>input</var>, optionally with a <a>base URL</a> <var>base</var>, opti
<dt><dfn>path start state</dfn>
<dd>
<ol>
<li><p>If <var>url</var> <a>is special</a> and <a>c</a> is "<code>\</code>",
<a>syntax violation</a>.
<li>
<p>If <var>url</var> <a>is special</a>, then:

<li><p>Set <var>state</var> to <a>path state</a>, and if neither <a>c</a> is
"<code>/</code>", nor <var>url</var> <a>is special</a> and <a>c</a> is
"<code>\</code>", decrease <var>pointer</var> by one.
<ol>
<li><p>If <a>c</a> is "<code>\</code>", <a>syntax violation</a>.

<li><p>Set <var>state</var> to <a>path state</a> and if <a>c</a> is neither "<code>/</code>"
nor "<code>\</code>", then decrease <var>pointer</var> by one.
</ol>

<li><p>Otherwise, if <var>state override</var> is not given and <a>c</a> is "<code>?</code>",
then set <var>url</var>'s <a for=url>query</a> to the empty string and <var>state</var> to
<a>query state</a>.

<li><p>Otherwise, if <var>state override</var> is not given and <a>c</a> is "<code>#</code>",
then set <var>url</var>'s <a for=url>fragment</a> to the empty string and <var>state</var> to
<a>fragment state</a>.

<li><p>Otherwise, if <a>c</a> is not <a>EOF code point</a>, then: set <var>state</var> to
<a>path state</a> and if <a>c</a> is not "<code>/</code>", then decrease <var>pointer</var> by
one.
</ol>

<dt><dfn>path state</dfn>
Expand Down Expand Up @@ -2087,9 +2108,8 @@ then runs these steps:
<li><p>If <var>url</var>'s <a for=url>cannot-be-a-base-URL flag</a> is set, append the first string
in <var>url</var>'s <a for=url>path</a> to <var>output</var>.

<li><p>Otherwise, append "<code>/</code>", followed by the strings in <var>url</var>'s
<a for=url>path</a> (including empty strings), separated from each other by
"<code>/</code>", to <var>output</var>.
<li><p>Otherwise, then <a for=list>for each</a> string in <var>url</var>'s <a for=url>path</a>,
append "<code>/</code>" followed by the string to <var>output</var>.

<li><p>If <var>url</var>'s <a for=url>query</a> is non-null, append
"<code>?</code>", followed by <var>url</var>'s <a for=url>query</a>, to
Expand Down Expand Up @@ -2638,6 +2658,9 @@ the setter to always "reset" both.
<li><p>If <a>context object</a>'s <a for=URL>url</a>'s <a for=url>cannot-be-a-base-URL flag</a> is
set, return the first string in <a>context object</a>'s <a for=URL>url</a>'s <a for=url>path</a>.

<li><p>If <a>context object</a>'s <a for=URL>url</a>'s <a for=url>path</a>
<a for=list>is empty</a>, then return the empty string.

<li><p>Return "<code>/</code>", followed by the strings in <a>context object</a>'s
<a for=URL>url</a>'s <a for=url>path</a> (including empty strings), separated from each other by
"<code>/</code>".
Expand Down

0 comments on commit 5e6d4e5

Please sign in to comment.