Skip to content

Commit

Permalink
Correct URL parsing of base elements
Browse files Browse the repository at this point in the history
Always parse <base> elements against the document's fallback base URL. When parsing fails, returns their href attribute value. (Note that it can only fail if there is an href attribute value.) This matches the semantics of "reflect", but does not directly use that mechanism since it does not support arbitrary base URLs and such.

Fixes #1060. (That issue also has links to tests and results for contemporary browsers.)
  • Loading branch information
annevk committed Apr 20, 2016
1 parent ef72f55 commit 2719a51
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -12094,9 +12094,10 @@ gave me some of the songs they wrote. I love sharing my music.&lt;/p>
data-x="attr-base-target">target</code> attributes, all but the first are ignored.</p>

<p>A <code>base</code> element that is the first <code>base</code> element with an <code
data-x="attr-base-href">href</code> content attribute in a particular <code>Document</code> has a
<dfn>frozen base URL</dfn>. The <span>frozen base URL</span> must be <span>immediately</span> <span data-x="set the frozen
base URL">set</span> for an element whenever any of the following situations occur:</p>
data-x="attr-base-href">href</code> content attribute <span>in a <code>Document</code></span> has
a <dfn>frozen base URL</dfn>. The <span>frozen base URL</span> must be <span>immediately</span>
<span data-x="set the frozen base URL">set</span> for an element whenever any of the following
situations occur:</p>

<ul class="brief">

Expand All @@ -12116,47 +12117,43 @@ gave me some of the songs they wrote. I love sharing my music.&lt;/p>
<ol>
<li><p>Let <var>document</var> be <var>element</var>'s <span>node document</span>.

<li><p><span data-x="parse a URL">Parse</span> the value of <var>element</var>'s <code
data-x="attr-base-href">href</code> content attribute relative to <var>document</var>.</p></li>

<li>
<p>If that algorithm fails or if running <span>Is base allowed for Document?</span> on the
<span>resulting URL record</span> and <var>document</var> returns "<code
data-x="">Blocked</code>", then set <var>element</var>'s <span>frozen base URL</span> to the
<span>fallback base URL</span>.</p>
<li><p>Let <var>urlRecord</var> be the result of <span data-x="URL parser">parsing</span> the
value of <var>element</var>'s <code data-x="attr-base-href">href</code> content attribute with
<var>document</var>'s <span>fallback base URL</span>, and <var>document</var>'s <span
data-x="document's character encoding">character encoding</span>. (Thus, the <code>base</code>
element isn't affected by itself.)</p></li>
<!-- This uses the URL parser rather than parse a URL since otherwise we'd have to unnessarily
complicate the latter for two callsites. -->

<p>Otherwise, set <var>element</var>'s <span>frozen base URL</span> to the <var>resulting URL
record</var>.</p>
</li>
<li><p>Set <var>element</var>'s <span>frozen base URL</span> to <var>document</var>'s
<span>fallback base URL</span>, if <var>urlRecord</var> is failure or running <span>Is base
allowed for Document?</span> on the <span>resulting URL record</span> and <var>document</var>
returns "<code data-x="">Blocked</code>", and to <var>urlRecord</var> otherwise.</p></li>
</ol>

<p>The <dfn><code data-x="dom-base-href">href</code></dfn> IDL attribute, on getting, must return
the result of running the following algorithm:
<!-- http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1715
https://github.com/whatwg/html/issues/1060#issuecomment-211221664 -->

<ol> <!-- http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1715 -->

<li><p>If the <code>base</code> element has no <code data-x="attr-base-href">href</code> content
attribute, then return the <span>document base URL</span> and abort these steps.</p></li>

<li><p>Let <var>fallback base url</var> be the <code>Document</code>'s <span>fallback
base URL</span>.</p></li>
<ol>
<li><p>Let <var>document</var> be <var>element</var>'s <span>node document</span>.

<li><p>Let <var>url</var> be the value of the <code data-x="attr-base-href">href</code>
attribute of the <code>base</code> element.</p></li>
attribute of this element, if it has one, and the empty string otherwise.</p></li>

<li><p>Let <var>urlRecord</var> be the result of <span data-x="URL parser">parsing</span>
<var>url</var> with <var>fallback base url</var>, and the <code>Document</code>'s <span
data-x="document's character encoding">character encoding</span>. (Thus, the <code>base</code>'s
<code data-x="attr-base-href">href</code> attribute isn't affected by other <code>base</code>
elements).</p></li>
<var>url</var> with <var>document</var>'s <span>fallback base URL</span>, and
<var>document</var>'s <span data-x="document's character encoding">character encoding</span>.
(Thus, the <code>base</code> element isn't affected by other <code>base</code> elements or
itself.)</p></li>
<!-- This uses the URL parser rather than parse a URL since otherwise we'd have to unnessarily
complicate the latter for this single callsite. -->
complicate the latter for two callsites. -->

<li><p>If <var>urlRecord</var> is failure, return the empty string.</p></li>
<li><p>If <var>urlRecord</var> is failure, return <var>url</var>.</p></li>

<li><p>Return the <span data-x="concept-url-serialiser">serialisation</span> of
<var>urlRecord</var>.</p></li>

</ol>

<p>The <code data-x="dom-base-href">href</code> IDL attribute, on setting, must set the <code
Expand Down

0 comments on commit 2719a51

Please sign in to comment.