Repository navigation
Add URL path equality and prefix comparison #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> | ||
|
|
@@ -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 | ||
| <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> | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 --> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)