Skip to content

Commit c230f55

Browse files
authored
Fix scrolling to fragments
Chrome and Safari both do a literal match first before using the decoded fragment. Edge does something very similar, though seems to differ in :target handling. Firefox would like to align per https://bugzilla.mozilla.org/show_bug.cgi?id=1380323 as our compliant behavior causes issues. Tests: web-platform-tests/wpt#6887. Fixes whatwg#2902.
1 parent a99b51e commit c230f55

1 file changed

Lines changed: 33 additions & 24 deletions

File tree

source

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82873,39 +82873,47 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O
8287382873
document</span> is.</p>
8287482874

8287582875
<ol>
82876+
<li><p>Let <var>fragment</var> be the document's <span data-x="concept-document-url">URL</span>'s
82877+
<span data-x="concept-url-fragment">fragment</span>.</p></li>
8287682878

82877-
<li><p>Apply the <span>URL parser</span> algorithm to the <span>URL</span>, and let <var>fragid</var> be the <span data-x="concept-url-fragment">fragment</span> component of the
82878-
resulting <span>URL record</span>.</p></li><!-- parsing can't fail, since we checked earlier on
82879-
when navigating -->
82879+
<li><p>If <var>fragment</var> is the empty string, then <span>the indicated part of the
82880+
document</span> is the top of the document; return.</p></li>
8288082881

82881-
<li><p>If <var>fragid</var> is the empty string, then <span>the indicated part of the
82882-
document</span> is the top of the document; stop the algorithm here.</p></li>
82882+
<li><p>If <span>find a potential indicated element</span> with <var>fragment</var> returns
82883+
non-null, than the return value is <span>the indicated part of the document</span>;
82884+
return.</p></li>
8288382885

82884-
<li><p>Let <var>fragid bytes</var> be the result of <span data-x="percent
82885-
decode">percent-decoding</span> <var>fragid</var>.</p></li>
82886+
<li><p>Let <var>fragmentBytes</var> be the result of <span data-x="percent
82887+
decode">percent-decoding</span> <var>fragment</var>.</p></li>
8288682888

82887-
<li><p>Let <var>decoded fragid</var> be the result of running <span>UTF-8 decode without BOM or
82888-
fail</span> on <var>fragid bytes</var>. If <var>decoded fragid</var> is failure, jump to the step
82889-
labeled <i>no decoded fragid</i>.</p></li>
82889+
<li><p>Let <var>decodedFragment</var> be the result of running <span>UTF-8 decode without BOM or
82890+
fail</span> on <var>fragmentBytes</var>.</p></li>
8289082891

82891-
<li><p>If there is an element <span data-x="in a document tree">in the document tree</span> that
82892-
has an <span data-x="concept-id">ID</span> exactly equal to <var>decoded fragid</var>, then the
82893-
first such element in <span>tree order</span> is <span>the indicated part of the document</span>;
82894-
stop the algorithm here.</p></li>
82892+
<li><p>If <span>find a potential indicated element</span> with <var>decodedFragment</var> returns
82893+
non-null, than the return value is <span>the indicated part of the document</span>;
82894+
return.</p></li>
8289582895

82896-
<li><p><i>No decoded fragid</i>: If there is an <code>a</code> element <span data-x="in a
82897-
document tree">in the document tree</span> that has a <code data-x="attr-a-name">name</code>
82898-
attribute whose value is exactly equal to <var>fragid</var> (<em>not</em> <var>decoded
82899-
fragid</var>), then the first such element in <span>tree order</span> is <span>the indicated part
82900-
of the document</span>; stop the algorithm here.</p></li>
82896+
<li><p>If <var>decodedFragment</var> is an <span>ASCII case-insensitive</span> match for the
82897+
string <code data-x="">top</code>, then <span>the indicated part of the document</span> is the
82898+
top of the document; return.</p></li>
8290182899

82902-
<li><p>If <var>fragid</var> is an <span>ASCII case-insensitive</span> match for the
82903-
string <code data-x="">top</code>, then <span>the indicated part of the document</span> is the top
82904-
of the document; stop the algorithm here.</p></li>
82900+
<li><p>There is no <span data-x="the indicated part of the document">indicated part of the
82901+
document</span>.</p></li>
82902+
</ol>
8290582903

82906-
<li><p>Otherwise, there is no <span data-x="the indicated part of the document">indicated part of
82907-
the document</span>.</p></li>
82904+
<p>To <dfn>find a potential indicated element</dfn> given a string <var>fragment</var>, run these
82905+
steps:</p>
8290882906

82907+
<ol>
82908+
<li><p>If there is an element <span data-x="in a document tree">in the document tree</span> that
82909+
has an <span data-x="concept-id">ID</span> equal to <var>fragment</var>, then return the first
82910+
such element in <span>tree order</span>.</p></li>
82911+
82912+
<li><p>If there is an <code>a</code> element <span data-x="in a document tree">in the document
82913+
tree</span> that has a <code data-x="attr-a-name">name</code> attribute whose value is equal to
82914+
<var>fragment</var>, then return the first such element in <span>tree order</span>.</p></li>
82915+
82916+
<li><p>Return null.</p></li>
8290982917
</ol>
8291082918

8291182919
<p>The <span>task source</span> for the task mentioned in this section must be the <span>DOM
@@ -120276,6 +120284,7 @@ INSERT INTERFACES HERE
120276120284
Allen Wirfs-Brock,
120277120285
Alex Komoroske,
120278120286
Alex Russell,
120287+
Alphan Chen,
120279120288
Ami Fischman,
120280120289
Amos Jeffries,
120281120290
Anders Carlsson,

0 commit comments

Comments
 (0)