Skip to content

Commit

Permalink
Define path segments and use them in the parser. Second part towards …
Browse files Browse the repository at this point in the history
…fixing #33.
  • Loading branch information
annevk committed Aug 16, 2015
1 parent 656b803 commit 99a4bf1
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 88 deletions.
84 changes: 50 additions & 34 deletions url.bs
Expand Up @@ -887,10 +887,11 @@ the following

<ul class=brief>
<li><p>a <a for=urlsyntax>scheme</a> that is an <a spec=dom>ASCII case-insensitive</a>
match for a <a>special scheme</a>, followed by a <a>scheme-relative URL</a>
match for a <a>special scheme</a>, followed by "<code>:</code>" and a
<a>scheme-relative URL</a>
<li><p>a <a for=urlsyntax>scheme</a> that is <em>not</em> an
<a spec=dom>ASCII case-insensitive</a> match for a <a>special scheme</a>, followed by a
<a>relative URL</a>
<a spec=dom>ASCII case-insensitive</a> match for a <a>special scheme</a>, followed by
"<code>:</code>" and a <a>relative URL</a>
</ul>

<p>either optionally followed by "<code>?</code>" and a <a for=urlsyntax>query</a>.
Expand All @@ -907,11 +908,17 @@ should be registered in the <cite>IANA URI [sic] Schemes</cite> registry.
must be a <a>relative URL</a>, followed by "<code>#</code>" and a
<a for=urlsyntax>fragment</a>.

<p>A <dfn export for=urlsyntax id=syntax-url-relative>relative URL</dfn> must be either a
<a>scheme-relative URL</a>, or a <a for=urlsyntax>path</a> that does not start with a
<a for=urlsyntax>scheme</a> and "<code>:</code>", optionally followed by a
"<code>?</code>" and a <a for=urlsyntax>query</a>.
<!-- XXX should really explain "." and ".." -->
<p>A <dfn export for=urlsyntax id=syntax-url-relative>relative URL</dfn> must be one of
the following

<ul class=brief>
<li><p>a <a>scheme-relative URL</a>
<li><p>a <a>path-absolute URL</a>
<li><p>a <a>path-relative URL</a> that does not start with a <a for=urlsyntax>scheme</a>
and "<code>:</code>"
</ul>

<p>any optionally followed by "<code>?</code>" and a <a for=urlsyntax>query</a>.

<p class="note no-backref">A non-null <a>base URL</a> is necessary when
<a lt="URL parser">parsing</a> a <a>relative URL</a>.
Expand All @@ -925,11 +932,32 @@ by "<code>:</code>" and a <a for=urlsyntax>port</a>, optionally followed by a
<a>ASCII digits</a>.

<p>A <dfn export for=urlsyntax id=syntax-url-path-absolute>path-absolute URL</dfn> must be
a <a for=urlsyntax>path</a> that starts with "<code>/</code>" and does not start with
"<code>//</code>".
"<code>/</code>" followed by a <a>path-relative URL</a>.

<p>A <dfn export for=urlsyntax id=syntax-url-path-relative>path-relative URL</dfn> must be
zero or more <a>path segments</a>, separated from each other by "<code>/</code>", and not
start with "<code>/</code>".

<p>A <dfn export for=urlsyntax id=syntax-url-path-segment>path segment</dfn> must be one
of the following

<ul class=brief>
<li><p>zero or more <a>URL units</a>, excluding "<code>/</code>" and "<code>?</code>",
that together are not a <a>single-dot path segment</a> or a
<a>double-dot path segment</a>.
<li><p>a <a>single-dot path segment</a>
<li><p>a <a>double-dot path segment</a>.
</ul>

<p>A
<dfn export for=urlsyntax id=syntax-url-path-segment-dot>single-dot path segment</dfn>
must be "<code>.</code>" or an <a spec=dom>ASCII case-insensitive</a> match for
"<code>%2e</code>".

<p>A <dfn export for=urlsyntax id=syntax-url-path>path</dfn> must be zero or more
<a>URL units</a>, excluding "<code>?</code>".
<p>A
<dfn export for=urlsyntax id=syntax-url-path-segment-dotdot>double-dot path segment</dfn>
must be "<code>..</code>" or an <a spec=dom>ASCII case-insensitive</a> match for one of
"<code>.%2e</code>", "<code>%2e.</code>", and "<code>%2e%2e</code>".

<p>A <dfn export for=urlsyntax id=syntax-url-query>query</dfn> must be zero or more
<a>URL units</a>.
Expand Down Expand Up @@ -1632,31 +1660,19 @@ optionally with an <a>encoding</a>
<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>buffer</var>, <a lt="ASCII lowercase">lowercased</a>, matches any row
in the first column of the following table, set <var>buffer</var> to the contents
of the cell in the second column of the matched row:

<table>
<tr><td>"<code>%2e</code>" <td>"<code>.</code>"
<tr><td>"<code>.%2e</code>" <td rowspan=3>"<code>..</code>"
<tr><td>"<code>%2e.</code>"
<tr><td>"<code>%2e%2e</code>"
</table>

<li><p>If <var>buffer</var> is "<code>..</code>", <a>pop</a> <var>url</var>'s
<a for=url>path</a>, and then if neither <a>c</a> is "<code>/</code>", nor
<var>url</var> <a>is special</a> and <a>c</a> is "<code>\</code>", append the empty
string to <var>url</var>'s <a for=url>path</a>.

<li><p>Otherwise, if <var>buffer</var> is "<code>.</code>" and if neither <a>c</a>
is "<code>/</code>", nor <var>url</var> <a>is special</a> and <a>c</a> is
"<code>\</code>", append the empty string to <var>url</var>'s
<li><p>If <var>buffer</var> is a <a>double-dot path segment</a>, <a>pop</a>
<var>url</var>'s <a for=url>path</a>, and then if neither <a>c</a> is
"<code>/</code>", nor <var>url</var> <a>is special</a> and <a>c</a> is
"<code>\</code>", append the empty string to <var>url</var>'s <a for=url>path</a>.

<li><p>Otherwise, if <var>buffer</var> is a <a>single-dot path segment</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>", append the empty string to <var>url</var>'s
<a for=url>path</a>.

<li>
<p>Otherwise, if <var>buffer</var> is not
"<code>.</code>", run these subsubsteps:
<p>Otherwise, if <var>buffer</var> is not a <a>single-dot path segment</a>, run
these subsubsteps:

<ol>
<li>
Expand Down
126 changes: 72 additions & 54 deletions url.html
Expand Up @@ -30,7 +30,7 @@
<h1 class="p-name no-ref allcaps" id="title">URL</h1>

<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard — Last Updated
<time class="dt-updated" datetime="2015-08-15">15 August 2015</time></span></h2>
<time class="dt-updated" datetime="2015-08-16">16 August 2015</time></span></h2>

<div data-fill-with="spec-metadata">
<dl>
Expand Down Expand Up @@ -1430,12 +1430,13 @@ <h3 class="heading settled" data-level="4.1" id="url-syntax"><span class="secno"

<li>
<p>a <a data-link-type="dfn" href="#syntax-url-scheme">scheme</a> that is an <a data-link-type="dfn" href="http://dom.spec.whatwg.org/#ascii-case_insensitive">ASCII case-insensitive</a>
match for a <a data-link-type="dfn" href="#special-scheme">special scheme</a>, followed by a <a data-link-type="dfn" href="#syntax-url-scheme-relative">scheme-relative URL</a>
match for a <a data-link-type="dfn" href="#special-scheme">special scheme</a>, followed by "<code>:</code>" and a
<a data-link-type="dfn" href="#syntax-url-scheme-relative">scheme-relative URL</a>
</p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-scheme">scheme</a> that is <em>not</em> an
<a data-link-type="dfn" href="http://dom.spec.whatwg.org/#ascii-case_insensitive">ASCII case-insensitive</a> match for a <a data-link-type="dfn" href="#special-scheme">special scheme</a>, followed by a
<a data-link-type="dfn" href="#syntax-url-relative">relative URL</a>
<a data-link-type="dfn" href="http://dom.spec.whatwg.org/#ascii-case_insensitive">ASCII case-insensitive</a> match for a <a data-link-type="dfn" href="#special-scheme">special scheme</a>, followed by
"<code>:</code>" and a <a data-link-type="dfn" href="#syntax-url-relative">relative URL</a>
</p></ul>


Expand All @@ -1456,11 +1457,25 @@ <h3 class="heading settled" data-level="4.1" id="url-syntax"><span class="secno"
<a data-link-type="dfn" href="#syntax-url-fragment">fragment</a>.

</p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-relative">relative URL<a class="self-link" href="#syntax-url-relative"></a></dfn> must be either a
<a data-link-type="dfn" href="#syntax-url-scheme-relative">scheme-relative URL</a>, or a <a data-link-type="dfn" href="#syntax-url-path">path</a> that does not start with a
<a data-link-type="dfn" href="#syntax-url-scheme">scheme</a> and "<code>:</code>", optionally followed by a
"<code>?</code>" and a <a data-link-type="dfn" href="#syntax-url-query">query</a>.
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-relative">relative URL<a class="self-link" href="#syntax-url-relative"></a></dfn> must be one of
the following

</p>
<ul class="brief">

<li>
<p>a <a data-link-type="dfn" href="#syntax-url-scheme-relative">scheme-relative URL</a>
</p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-path-absolute">path-absolute URL</a>
</p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-path-relative">path-relative URL</a> that does not start with a <a data-link-type="dfn" href="#syntax-url-scheme">scheme</a>
and "<code>:</code>"
</p></ul>


<p>any optionally followed by "<code>?</code>" and a <a data-link-type="dfn" href="#syntax-url-query">query</a>.

</p>
<p class="note no-backref" role="note">A non-null <a data-link-type="dfn" href="#concept-base-url">base URL</a> is necessary when
Expand All @@ -1478,12 +1493,43 @@ <h3 class="heading settled" data-level="4.1" id="url-syntax"><span class="secno"

</p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-absolute">path-absolute URL<a class="self-link" href="#syntax-url-path-absolute"></a></dfn> must be
a <a data-link-type="dfn" href="#syntax-url-path">path</a> that starts with "<code>/</code>" and does not start with
"<code>//</code>".
"<code>/</code>" followed by a <a data-link-type="dfn" href="#syntax-url-path-relative">path-relative URL</a>.

</p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path">path<a class="self-link" href="#syntax-url-path"></a></dfn> must be zero or more
<a data-link-type="dfn" href="#url-units">URL units</a>, excluding "<code>?</code>".
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-relative">path-relative URL<a class="self-link" href="#syntax-url-path-relative"></a></dfn> must be
zero or more <a data-link-type="dfn" href="#syntax-url-path-segment">path segments</a>, separated from each other by "<code>/</code>", and not
start with "<code>/</code>".

</p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-segment">path segment<a class="self-link" href="#syntax-url-path-segment"></a></dfn> must be one
of the following

</p>
<ul class="brief">

<li>
<p>zero or more <a data-link-type="dfn" href="#url-units">URL units</a>, excluding "<code>/</code>" and "<code>?</code>",
that together are not a <a data-link-type="dfn" href="#syntax-url-path-segment-dot">single-dot path segment</a> or a
<a data-link-type="dfn" href="#syntax-url-path-segment-dotdot">double-dot path segment</a>.
</p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-path-segment-dot">single-dot path segment</a>
</p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-path-segment-dotdot">double-dot path segment</a>.
</p></ul>


<p>A
<dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-segment-dot">single-dot path segment<a class="self-link" href="#syntax-url-path-segment-dot"></a></dfn>
must be "<code>.</code>" or an <a data-link-type="dfn" href="http://dom.spec.whatwg.org/#ascii-case_insensitive">ASCII case-insensitive</a> match for
"<code>%2e</code>".

</p>
<p>A
<dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-segment-dotdot">double-dot path segment<a class="self-link" href="#syntax-url-path-segment-dotdot"></a></dfn>
must be "<code>..</code>" or an <a data-link-type="dfn" href="http://dom.spec.whatwg.org/#ascii-case_insensitive">ASCII case-insensitive</a> match for one of
"<code>.%2e</code>", "<code>%2e.</code>", and "<code>%2e%2e</code>".

</p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-query">query<a class="self-link" href="#syntax-url-query"></a></dfn> must be zero or more
Expand Down Expand Up @@ -2587,51 +2633,23 @@ <h3 class="heading settled" data-level="4.2" id="url-parsing"><span class="secno

</p>
<li>

<p>If <var>buffer</var>, <a data-link-type="dfn" href="#ascii-lowercase">lowercased</a>, matches any row
in the first column of the following table, set <var>buffer</var> to the contents
of the cell in the second column of the matched row:

</p>
<table>

<tbody>
<tr>
<td>"<code>%2e</code>"
<td>"<code>.</code>"

<tr>
<td>"<code>.%2e</code>"
<td rowspan="3">"<code>..</code>"

<tr>
<td>"<code>%2e.</code>"

<tr>
<td>"<code>%2e%2e</code>"

</table>



<li>
<p>If <var>buffer</var> is "<code>..</code>", <a data-link-type="dfn" href="#pop-a-urls-path">pop</a> <var>url</var>’s
<a data-link-type="dfn" href="#concept-url-path">path</a>, and then if neither <a data-link-type="dfn" href="#c">c</a> is "<code>/</code>", nor
<var>url</var> <a data-link-type="dfn" href="#is-special">is special</a> and <a data-link-type="dfn" href="#c">c</a> is "<code>\</code>", append the empty
string to <var>url</var>’s <a data-link-type="dfn" href="#concept-url-path">path</a>.
<p>If <var>buffer</var> is a <a data-link-type="dfn" href="#syntax-url-path-segment-dotdot">double-dot path segment</a>, <a data-link-type="dfn" href="#pop-a-urls-path">pop</a>
<var>url</var>’s <a data-link-type="dfn" href="#concept-url-path">path</a>, and then if neither <a data-link-type="dfn" href="#c">c</a> is
"<code>/</code>", nor <var>url</var> <a data-link-type="dfn" href="#is-special">is special</a> and <a data-link-type="dfn" href="#c">c</a> is
"<code>\</code>", append the empty string to <var>url</var>’s <a data-link-type="dfn" href="#concept-url-path">path</a>.

</p>
<li>
<p>Otherwise, if <var>buffer</var> is "<code>.</code>" and if neither <a data-link-type="dfn" href="#c">c</a>
is "<code>/</code>", nor <var>url</var> <a data-link-type="dfn" href="#is-special">is special</a> and <a data-link-type="dfn" href="#c">c</a> is
"<code>\</code>", append the empty string to <var>url</var>’s
<p>Otherwise, if <var>buffer</var> is a <a data-link-type="dfn" href="#syntax-url-path-segment-dot">single-dot path segment</a> and if
neither <a data-link-type="dfn" href="#c">c</a> is "<code>/</code>", nor <var>url</var> <a data-link-type="dfn" href="#is-special">is special</a> and
<a data-link-type="dfn" href="#c">c</a> is "<code>\</code>", append the empty string to <var>url</var>’s
<a data-link-type="dfn" href="#concept-url-path">path</a>.

</p>
<li>

<p>Otherwise, if <var>buffer</var> is not
"<code>.</code>", run these subsubsteps:
<p>Otherwise, if <var>buffer</var> is not a <a data-link-type="dfn" href="#syntax-url-path-segment-dot">single-dot path segment</a>, run
these subsubsteps:

</p>
<ol>
Expand Down Expand Up @@ -4772,6 +4790,7 @@ <h3 class="no-num heading settled" id="index-defined-here"><span class="content"
<li><a href="#dom-url-domaintoascii">domainToASCII(domain)</a><span>, in §6.2</span>
<li><a href="#concept-domain-to-unicode">domain to Unicode</a><span>, in §3.1</span>
<li><a href="#dom-url-domaintounicode">domainToUnicode(domain)</a><span>, in §6.2</span>
<li><a href="#syntax-url-path-segment-dotdot">double-dot path segment</a><span>, in §4.1</span>
<li><a href="#eof-code-point">EOF code point</a><span>, in §1.1</span>
<li><a href="#equals">equals</a><span>, in §4.4</span>
<li><a href="#file-host-state">file host state</a><span>, in §4.2</span>
Expand Down Expand Up @@ -4851,14 +4870,12 @@ <h3 class="no-num heading settled" id="index-defined-here"><span class="content"
<li><a href="#concept-url-password">dfn for url</a><span>, in §4</span>
<li><a href="#dom-urlutils-password">attribute for URLUtils, URLUtilsReadOnly</a><span>, in §6.3</span>
</ul>
<li>path
<ul>
<li><a href="#concept-url-path">dfn for url</a><span>, in §4</span>
<li><a href="#syntax-url-path">dfn for urlsyntax</a><span>, in §4.1</span>
</ul>
<li><a href="#concept-url-path">path</a><span>, in §4</span>
<li><a href="#syntax-url-path-absolute">path-absolute URL</a><span>, in §4.1</span>
<li><a href="#dom-urlutils-pathname">pathname</a><span>, in §6.3</span>
<li><a href="#path-or-authority-state">path or authority state</a><span>, in §4.2</span>
<li><a href="#syntax-url-path-relative">path-relative URL</a><span>, in §4.1</span>
<li><a href="#syntax-url-path-segment">path segment</a><span>, in §4.1</span>
<li><a href="#path-start-state">path start state</a><span>, in §4.2</span>
<li><a href="#path-state">path state</a><span>, in §4.2</span>
<li><a href="#percent-decode">percent decode</a><span>, in §2</span>
Expand Down Expand Up @@ -4907,6 +4924,7 @@ <h3 class="no-num heading settled" id="index-defined-here"><span class="content"
<li><a href="#set-the-password">set the password</a><span>, in §4.2</span>
<li><a href="#set-the-username">set the username</a><span>, in §4.2</span>
<li><a href="#simple-encode-set">simple encode set</a><span>, in §2</span>
<li><a href="#syntax-url-path-segment-dot">single-dot path segment</a><span>, in §4.1</span>
<li><a href="#special-authority-ignore-slashes-state">special authority ignore slashes state</a><span>, in §4.2</span>
<li><a href="#special-authority-slashes-state">special authority slashes state</a><span>, in §4.2</span>
<li><a href="#special-relative-or-authority-state">special relative or authority state</a><span>, in §4.2</span>
Expand Down

0 comments on commit 99a4bf1

Please sign in to comment.