Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 72 additions & 6 deletions url.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1947,11 +1947,18 @@ the <a>blob URL store</a> between parsing and fetching, while fetching will stil
<hr>

<p>A <dfn export>URL path</dfn> is either a <a>URL path segment</a> or a <a for=/>list</a> of zero
or more <a>URL path segments</a>.
or more <a>URL path segments</a>. In the latter case the <a>URL path segments</a> never contain
U+002F (/).

<p>A <dfn export>URL path segment</dfn> is an <a for=/>ASCII string</a>. It commonly refers to a
directory or a file, but has no predefined meaning.

<p class=note>A <a for=/>URL path</a> that is a <a>URL path segment</a> is
<a for=url lt="opaque path">opaque</a> and can contain U+002F (/), as with
<code>web+demo:a/b</code>. The <a>URL parser</a> never produces one that starts with U+002F (/), but
<cite>URL Pattern</cite> does while canonicalizing patterns, so that is not an invariant.
[[URLPATTERN]]

<p>A
<dfn export id=single-dot-path-segment oldids=syntax-url-path-segment-dot>single-dot URL path segment</dfn>
is a <a for=/>URL path segment</a> that is "<code>.</code>" or an <a>ASCII case-insensitive</a>
Expand Down Expand Up @@ -3220,16 +3227,19 @@ these steps. They return an <a>ASCII string</a>.

<div algorithm>
<p>The <dfn export lt="URL path serializer|URL path serializing">URL path serializer</dfn> takes a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels subjectively icky. I'd rather have two algorithms which take well-defined types, with one delegating to the other. It'd be a bonus if the one that takes a path could stay non-exported.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided to keep this as-is. I don't think it's too bad. (I did investigate only having one, but that impacts too many downstream specifications.)

<a for=/>URL</a> <var>url</var> and then runs these steps. They return an <a>ASCII string</a>.
<a for=/>URL</a> or <a for=/>URL path</a> <var>urlOrPath</var> and then runs these steps. They
return an <a>ASCII string</a>.

<ol>
<li><p>If <var>url</var> has an <a for=url>opaque path</a>, then return <var>url</var>'s
<a for=url>path</a>.
<li><p>Let <var>path</var> be <var>urlOrPath</var>'s <a for=url>path</a> if <var>urlOrPath</var> is
a <a for=/>URL</a>; otherwise <var>urlOrPath</var>.

<li><p>If <var>path</var> is a <a for=/>URL path segment</a>, then return <var>path</var>.

<li><p>Let <var>output</var> be the empty string.

<li><p><a for=list>For each</a> <var>segment</var> of <var>url</var>'s <a for=url>path</a>: append
U+002F (/) followed by <var>segment</var> to <var>output</var>.
<li><p><a for=list>For each</a> <var>segment</var> of <var>path</var>: append U+002F (/) followed
by <var>segment</var> to <var>output</var>.

<li><p>Return <var>output</var>.
</ol>
Expand Down Expand Up @@ -3257,6 +3267,62 @@ run these steps:
</ol>
</div>

<div algorithm="path equal">
<p>To determine whether a <a for=/>URL path</a> <var>A</var>
<dfn export for="URL path" lt=equal>equals</dfn> <a for=/>URL path</a> <var>B</var>, run these
steps. They return a boolean.

<ol>
<li><p>If <var>A</var> is a <a for=/>URL path segment</a> or <var>B</var> is a
<a for=/>URL path segment</a>, then return whether <var>A</var> <a for=string>is</a> <var>B</var>.

<li><p>If <var>A</var>'s <a for=list>size</a> is not <var>B</var>'s <a for=list>size</a>, then
return false.

<li><p><a for=list>For each</a> <var>index</var> of <var>A</var>'s <a for=list>indices</a>: if

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess whatwg/infra#710 would be useful here, but stalled.

<var>A</var>[<var>index</var>] is not <var>B</var>[<var>index</var>], then return false.

<li><p>Return true.
</ol>

<p class=note>Comparing <a for=/>URL path segments</a> rather than serializations can matter as
distinct <a for=/>URL paths</a> can <a lt="URL path serializer">serialize</a> identically. E.g.,
<code>web+demo:</code>'s <a for=url>path</a> is the empty string, whereas
<code>web+demo://host</code>'s <a for=url>path</a> is « », and both serialize to the empty string.
</div>

<div algorithm="path starts with">
<p>To determine whether a <a for=/>URL path</a> <var>A</var>
<dfn export for="URL path" lt="start with|starts with">starts with</dfn> <a for=/>URL path</a>
<var>B</var>, run these steps. They return a boolean.

<ol>
<li><p>If <var>A</var> is a <a for=/>URL path segment</a> or <var>B</var> is a
<a for=/>URL path segment</a>, then return false.

<li><p>If <var>B</var>'s <a for=list>size</a> is greater than <var>A</var>'s
<a for=list>size</a>, then return false.

<li><p><a for=list>For each</a> <var>index</var> of <var>B</var>'s <a for=list>indices</a>: if
<var>A</var>[<var>index</var>] is not <var>B</var>[<var>index</var>], then return false.

<li><p>Return true.
</ol>

<p class=note>As <a for=/>URL path segments</a> in a <a for=/>list</a> never contain U+002F (/),
<var>A</var> starts with <var>B</var> only when <var>B</var> covers whole segments of <var>A</var>.
This makes it suitable for deciding whether one <a for=/>URL path</a> is "contained" by another.
Comparing <a lt="URL path serializer">serializations</a> cannot be done naïvely: the serialization
of « "<code>foobar</code>" » <a for=string>starts with</a> the serialization of
« "<code>foo</code>" », but a <a for=/>URL</a> with the latter <a for=url>path</a> does not
contain a <a for=/>URL</a> with the former.

<p class=warning>Specifications should prefer the <a for=/>origin</a> concept for security
decisions. Treating a <a for=/>URL path</a> as covering the <a for=/>URL paths</a> it contains is a
form of path-based authority that is discordant with the rest of the web platform. It is needed for
legacy features, such as cookies, and is best avoided elsewhere.
</div>


<h3 id=origin>Origin</h3>
<!-- Still need to watch the final bits -->
Expand Down