Skip to content

Commit

Permalink
Editorial: add parse and serialize a URL
Browse files Browse the repository at this point in the history
This is the first step towards making parse a URL always return a URL record rather than a somewhat awkward tuple.
  • Loading branch information
annevk committed Sep 6, 2023
1 parent cc7652e commit a13cfbe
Showing 1 changed file with 103 additions and 81 deletions.
184 changes: 103 additions & 81 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -7070,19 +7070,19 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
match that of the document or environment settings object for legacy reasons. When that is not the
case the <span>URL parser</span> can be used directly.</p>

<p id="resolve-a-url">To <dfn>parse a URL</dfn> <var>url</var>, relative to either a
<var>document</var> or <var>environment settings object</var>, the user agent must use the
following steps. Parsing a URL either results in failure or a <span>resulting URL string</span>
and <span>resulting URL record</span>.</p>
<p id="resolve-a-url">To <dfn>parse a URL</dfn> <var>url</var>, relative to a
<code>Document</code> object or <span>environment settings object</span> <var>environment</var>,
run these steps. They return failure or a <span>resulting URL string</span> and <span>resulting
URL record</span>.</p>

<ol>
<li><p>Let <var>encoding</var> be <var>document</var>'s <span data-x="document's character
encoding">character encoding</span>, if <var>document</var> was given, and <var>environment
settings object</var>'s <span>API URL character encoding</span> otherwise.</p></li>
<li><p>Let <var>encoding</var> be <var>environment</var>'s <span data-x="document's character
encoding">character encoding</span>, if <var>environment</var> is a <code>Document</code> object;
otherwise <var>environment</var>'s <span>API URL character encoding</span>.</p></li>

<li><p>Let <var>baseURL</var> be <var>document</var>'s <span data-x="document base URL">base
URL</span>, if <var>document</var> was given, and <var>environment settings object</var>'s
<span>API base URL</span> otherwise.</p></li>
<li><p>Let <var>baseURL</var> be <var>environment</var>'s <span data-x="document base URL">base
URL</span>, if <var>environment</var> is a <code>Document</code> object; otherwise
<var>environment</var>'s <span>API base URL</span> otherwise.</p></li>

<li><p>Let <var>urlRecord</var> be the result of applying the <span>URL parser</span> to
<var>url</var>, with <var>baseURL</var> and <var>encoding</var>.</p></li>
Expand All @@ -7096,6 +7096,17 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<var>urlRecord</var> as the <dfn>resulting URL record</dfn>.</p></li>
</ol>

<p>To <dfn data-x="parsing and serializing a URL">parse and serialize a URL</dfn> <var>url</var>,
relative to a <code>Document</code> object or <span>environment settings object</span>
<var>environment</var>, run these steps. They return failure or a string.</p>

<ol>
<li><p><span>Parse a URL</span> <var>url</var>, relative to <var>environment</var>. If that
returns failure, then return failure.</p></li>

<li><p>Return the <span>resulting URL string</span>.</p></li>
</ol>

</div>


Expand Down Expand Up @@ -7999,11 +8010,11 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<ol>
<li><p>If <var>contentAttributeValue</var> is null, then return the empty string.</p></li>

<li><p><span data-x="parse a url">Parse</span> <var>contentAttributeValue</var> relative to
the element's <span>node document</span>.</p></li>
<li><p>Let <var>urlString</var> be the result of <span>parsing and serializing a URL</span>
given <var>contentAttributeValue</var>, relative to <var>element</var>'s <span>node
document</span>.</p></li>

<li><p>If that does not return failure, then return the <span>resulting URL
string</span>.</p></li>
<li><p>If <var>urlString</var> is not failure, then return <var>urlString</var>.</p></li>
</ol>
</li>

Expand Down Expand Up @@ -25158,18 +25169,14 @@ document.body.appendChild(wbr);</code></pre>

<li><p>If <var>targetNavigable</var> is null, then return.</p></li>

<li><p><span>Parse a URL</span> given <var>subject</var>'s <code
data-x="attr-hyperlink-href">href</code> attribute, relative to <var>subject</var>'s <span>node
document</span>.</p></li>

<li>
<p>If that is successful, let <var>url</var> be the <span>resulting URL string</span>.</p>
<li><p>Let <var>urlString</var> be the result of <span>parsing and serializing a URL</span> given
<var>subject</var>'s <code data-x="attr-hyperlink-href">href</code> attribute value, relative to
<var>subject</var>'s <span>node document</span>.</p></li>

<p>Otherwise, if <span data-x="parse a url">parsing</span> the <span>URL</span> failed, then
return.</p>
</li>
<li><p>If <var>urlString</var> is failure, then return.</p></li>

<li><p>If <var>hyperlinkSuffix</var> is non-null, then append it to <var>url</var>.</p></li>
<li><p>If <var>hyperlinkSuffix</var> is non-null, then append it to
<var>urlString</var>.</p></li>

<li><p>Let <var>referrerPolicy</var> be the current state of <var>subject</var>'s <code
data-x="">referrerpolicy</code> content attribute.</p></li>
Expand All @@ -25179,8 +25186,8 @@ document.body.appendChild(wbr);</code></pre>
<var>referrerPolicy</var> to "<code data-x="">no-referrer</code>".</p></li>

<li>
<p><span>Navigate</span><!--DONAV hyperlink--> <var>targetNavigable</var> to <var>url</var>
using <var>subject</var>'s <span>node document</span>, with <i
<p><span>Navigate</span><!--DONAV hyperlink--> <var>targetNavigable</var> to
<var>urlString</var> using <var>subject</var>'s <span>node document</span>, with <i
data-x="navigation-referrer-policy">referrerPolicy</i> set to <var>referrerPolicy</var> and <i
data-x="navigation-user-involvement">userInvolvement</i> set to <var>userInvolvement</var>.</p>

Expand Down Expand Up @@ -25234,15 +25241,14 @@ document.body.appendChild(wbr);</code></pre>
sandboxing flag set</span> has the <span>sandboxed downloads browsing context flag</span> set,
then return.</p></li>

<li><p><span>Parse a URL</span> given <var>subject</var>'s <code
data-x="attr-hyperlink-href">href</code> attribute, relative to <var>subject</var>'s <span>node
document</span>.</p></li>
<li><p>Let <var>urlString</var> be the result of <span>parsing and serializing a URL</span> given
<var>subject</var>'s <code data-x="attr-hyperlink-href">href</code> attribute value, relative to
<var>subject</var>'s <span>node document</span>.</p></li>

<li><p>If <span data-x="parse a url">parsing the URL</span> fails, then return.</p>
<li><p>If <var>urlString</var> is failure, then return.</p></li>

<li><p>Otherwise, let <var>url</var> be the <span>resulting URL string</span>.</p></li>

<li><p>If <var>hyperlinkSuffix</var> is non-null, then append it to <var>url</var>.</p></li>
<li><p>If <var>hyperlinkSuffix</var> is non-null, then append it to
<var>urlString</var>.</p></li>

<li>
<p>If <var>userInvolvement</var> is not "<code data-x="uni-browser-ui">browser UI</code>",
Expand All @@ -25261,9 +25267,10 @@ document.body.appendChild(wbr);</code></pre>
<li><p>Let <var>continue</var> be the result of <span data-x="fire a download request navigate
event">firing a download request <code data-x="event-navigate">navigate</code> event</span> at
<var>navigation</var> with <i data-x="fire-navigate-download-destinationURL">destinationURL</i>
set to <var>url</var>, <i data-x="fire-navigate-download-userInvolvement">userInvolvement</i>
set to <var>userInvolvement</var>, and <i data-x="fire-navigate-download-filename">filename</i>
set to <var>filename</var>.</p></li>
set to <var>urlString</var>, <i
data-x="fire-navigate-download-userInvolvement">userInvolvement</i> set to
<var>userInvolvement</var>, and <i data-x="fire-navigate-download-filename">filename</i> set to
<var>filename</var>.</p></li>

<li><p>If <var>continue</var> is false, then return.</p></li>
</ol>
Expand All @@ -25277,10 +25284,10 @@ document.body.appendChild(wbr);</code></pre>
safeguard the user from a potentially hostile download.</p></li>

<li><p>Let <var>request</var> be a new <span data-x="concept-request">request</span> whose
<span data-x="concept-request-url">URL</span> is <var>url</var>,
<span data-x="concept-request-client">client</span> is <span>entry settings object</span>,
<span data-x="concept-request-initiator">initiator</span> is "<code data-x="">download</code>",
<span data-x="concept-request-destination">destination</span> is the empty string, and whose
<span data-x="concept-request-url">URL</span> is <var>urlString</var>, <span
data-x="concept-request-client">client</span> is <span>entry settings object</span>, <span
data-x="concept-request-initiator">initiator</span> is "<code data-x="">download</code>", <span
data-x="concept-request-destination">destination</span> is the empty string, and whose
<span>synchronous flag</span> and <span>use-URL-credentials flag</span> are set.</p></li>

<!--FETCH--><li><p>Handle the result of <span data-x="concept-fetch">fetching</span>
Expand Down Expand Up @@ -25485,9 +25492,9 @@ document.body.appendChild(wbr);</code></pre>
data-x="">ping</code>".</p></li>

<li>
<p>Let <var>target URL</var> be the <span>resulting URL string</span> obtained from <span
data-x="parse a url">parsing</span> the value of the element's <code
data-x="attr-hyperlink-href">href</code> attribute and then:</p>
<p>Let <var>target URL</var> be the result of <span>parsing and serializing a URL</span> given
the element's <code data-x="attr-hyperlink-href">href</code> attribute value, relative to the
element's <span>node document</span>, and then:</p>

<dl class="switch">
<dt>If the <span data-x="concept-document-url">URL</span> of the <code>Document</code> object
Expand Down Expand Up @@ -30464,11 +30471,13 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code
<p>If <var>selected source</var> is not null, then:</p>

<ol>
<li><p><span data-x="parse a url">Parse</span> <var>selected source</var>, relative to the
element's <span>node document</span>. If that is not successful, then abort this inner set of
steps. Otherwise, let <var>urlString</var> be the <span>resulting URL string</span>.</p></li>
<li><p>Let <var>urlString</var> be the result of <span>parsing and serializing a URL</span>
given <var>selected source</var>, relative to the element's <span>node
document</span>.</p></li>
<!-- This does not change currentSrc -->

<li><p>If <var>urlString</var> is failure, then abort this inner set of steps.</p></li>

<li><p>Let <var>key</var> be a tuple consisting of <var>urlString</var>, the <code>img</code>
element's <code data-x="attr-img-crossorigin">crossorigin</code> attribute's mode, and, if that
mode is not <span data-x="attr-crossorigin-none">No CORS</span>, the <span>node
Expand Down Expand Up @@ -30576,10 +30585,11 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code
</ol>
</li>

<li><p>Let <var>urlString</var> be the result of <span>parsing and serializing a URL</span> given
<var>selected source</var>, relative to the element's <span>node document</span>.</p></li>

<li>
<p><span data-x="parse a url">Parse</span> <var>selected source</var>, relative to the element's
<span>node document</span>, and let <var>urlString</var> be the <span>resulting URL
string</span>. If that is not successful, then:</p>
<p>If <var>urlString</var> is failure, then:</p>

<ol>
<li><p><span>Abort the image request</span> for the <span>current request</span> and the
Expand Down Expand Up @@ -31530,9 +31540,11 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code
base URL resolution, so changing the base URL doesn't trigger an update if nothing else changed
-->

<li><p>&#x231B; <span data-x="parse a url">Parse</span> <var>selected source</var>, relative to
the element's <span>node document</span>, and let <var>urlString</var> be the <span>resulting URL
string</span>. If that is not successful, then return.</p></li>
<li><p>&#x231B; Let <var>urlString</var> be the result of <span>parsing and serializing a
URL</span> given <var>selected source</var>, relative to the element's <span>node
document</span>.</p></li>

<li><p>&#x231B; If <var>urlString</var> is failure, then return.</p></li>

<li><p>&#x231B; Let <var>corsAttributeState</var> be the state of the element's <code
data-x="attr-img-crossorigin">crossorigin</code> content attribute.</p></li>
Expand Down Expand Up @@ -34904,11 +34916,23 @@ interface <dfn interface>HTMLTrackElement</dfn> : <span>HTMLElement</span> {

<div w-nodev>

<p>If the element has a <code data-x="attr-track-src">src</code> attribute whose value is not the
empty string and whose value, when the attribute was set, could be successfully <span
data-x="parse a url">parsed</span> relative to the element's <span>node document</span>, then the
element's <dfn>track URL</dfn> is the <span>resulting URL string</span>. Otherwise, the element's
<span>track URL</span> is the empty string.</p>
<p>The element has an associated <dfn>track URL</dfn> (a string), initially the empty string.</p>

<p>When the element's <code data-x="attr-track-src">src</code> attribute is set, run these steps:

<ol>
<li><p>Let <var>trackURL</var> be failure.</p></li>

<li><p>Let <var>value</var> be the element's <code data-x="attr-track-src">src</code> attribute
value.</p></li>

<li><p>If <var>value</var> is not the empty string, then set <var>trackURL</var> to the result of
<span>parsing and serializing a URL</span> given <var>value</var>, relative to the element's
<span>node document</span>.</p></li>

<li><p>Set the element's <span>track URL</span> to <var>trackURL</var> if it is not failure;
otherwise to the empty string.</p></li>
</ol>

</div>

Expand Down Expand Up @@ -74199,33 +74223,30 @@ Demos:
<code>img</code>, <code>source</code>, <code>track</code>, or <code>video</code> element</dt>

<dd>
<p>The value is the <span>resulting URL string</span> that results from <span data-x="parse a
url">parsing</span> the value of the element's <code data-x="">src</code> attribute relative to
the <span>node document</span> of the element at the time the attribute is set, or the empty
string if there is no such attribute or if <span data-x="parse a url">parsing</span> it results
in an error.</p>
<p>The value is the result of <span>parsing and serializing a URL</span> given the element's
<code data-x="">src</code> attribute value, relative to the element's <span>node
document</span>, at the time the attribute is set, or the empty string if there is no such
attribute or the result is failure.</p>
</dd>


<dt>If the element is an <code>a</code>, <code>area</code>, or <code>link</code> element</dt>

<dd>
<p>The value is the <span>resulting URL string</span> that results from <span data-x="parse a
url">parsing</span> the value of the element's <code data-x="">href</code> attribute relative to
the <span>node document</span> of the element at the time the attribute is set, or the empty
string if there is no such attribute or if <span data-x="parse a url">parsing</span> it results
in an error.</p>
<p>The value is the result of <span>parsing and serializing a URL</span> given the element's
<code data-x="">href</code> attribute value, relative to the element's <span>node
document</span>, at the time the attribute is set, or the empty string if there is no such
attribute or the result is failure.</p>
</dd>


<dt>If the element is an <code>object</code> element</dt>

<dd>
<p>The value is the <span>resulting URL string</span> that results from <span data-x="parse a
url">parsing</span> the value of the element's <code data-x="">data</code> attribute relative to
the <span>node document</span> of the element at the time the attribute is set, or the empty
string if there is no such attribute or if <span data-x="parse a url">parsing</span> it results
in an error.</p>
<p>The value is the result of <span>parsing and serializing a URL</span> given the element's
<code data-x="">data</code> attribute value, relative to the element's <span>node
document</span>, at the time the attribute is set, or the empty string if there is no such
attribute or the result is failure.</p>
</dd>


Expand Down Expand Up @@ -128717,11 +128738,11 @@ html, body { display: block; }</code></pre>
<hr>

<p>When a <code>body</code> element has a <code data-x="attr-background">background</code>
attribute set to a non-empty value, the new value is expected to be <span data-x="parse a
url">parsed</span> relative to the element's <span>node document</span>, and if this is
successful, the user agent is expected to treat the attribute as a <span data-x="presentational
hints">presentational hint</span> setting the element's <span>'background-image'</span> property
to the <span>resulting URL string</span>.</p>
attribute set to a non-empty value, the new value is expected to be <span data-x="parsing and
serializing a URL">parsed and serialized</span> relative to the element's <span>node
document</span>, and if that does not return failure, the user agent is expected to treat the
attribute as a <span data-x="presentational hints">presentational hint</span> setting the
element's <span>'background-image'</span> property to the return value.</p>

<p>When a <code>body</code> element has a <code data-x="attr-body-bgcolor">bgcolor</code>
attribute set, the new value is expected to be parsed using the <span>rules for parsing a legacy
Expand Down Expand Up @@ -129563,10 +129584,11 @@ table {
<p>When a <code>table</code>, <code>thead</code>, <code>tbody</code>, <code>tfoot</code>,
<code>tr</code>, <code>td</code>, or <code>th</code> element has a <code
data-x="attr-background">background</code> attribute set to a non-empty value, the new value is
expected to be <span data-x="parse a url">parsed</span> relative to the element's <span>node
document</span>, and if this is successful, the user agent is expected to treat the attribute as a
<span data-x="presentational hints">presentational hint</span> setting the element's
<span>'background-image'</span> property to the <span>resulting URL string</span>.</p>
expected to be <span data-x="parsing and serializing a URL">parsed and serialized</span> relative
to the element's <span>node document</span>, and if that does not return failure, the user agent
is expected to treat the attribute as a <span data-x="presentational hints">presentational
hint</span> setting the element's <span>'background-image'</span> property to the return
value.</p>

<p>When a <code>table</code>, <code>thead</code>, <code>tbody</code>, <code>tfoot</code>,
<code>tr</code>, <code>td</code>, or <code>th</code> element has a <code data-x="">bgcolor</code>
Expand Down

0 comments on commit a13cfbe

Please sign in to comment.