Skip to content

Commit 55baf05

Browse files
authored
Prevent infinite loop in revealing algorithms
The ancestor details revealing algorithm and the hidden until found revealing algorithm may both get stuck in infinite loops because they iterate the flat tree while firing synchronous events. If the page were to listen to these events and change the flat tree in response, then the algorithm could theoretically never end. Fixes #11436.
1 parent 917c2f6 commit 55baf05

File tree

1 file changed

+64
-54
lines changed

1 file changed

+64
-54
lines changed

source

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -61902,35 +61902,6 @@ interface <dfn interface>HTMLDetailsElement</dfn> : <span>HTMLElement</span> {
6190261902

6190361903
</div>
6190461904

61905-
<p>The <dfn>ancestor details revealing algorithm</dfn> is to run the following steps on
61906-
<var>currentNode</var>:</p>
61907-
61908-
<ol>
61909-
<li>
61910-
<p>While <var>currentNode</var> has a parent node within the <span>flat tree</span>:</p>
61911-
61912-
<ol>
61913-
<li>
61914-
<p>If <var>currentNode</var> is slotted into the second slot of a <code>details</code>
61915-
element:</p>
61916-
61917-
<ol>
61918-
<li><p>Set <var>currentNode</var> to the <code>details</code> element which
61919-
<var>currentNode</var> is slotted into.</p></li>
61920-
61921-
<li><p>If the <code data-x="attr-details-open">open</code> attribute is not set on
61922-
<var>currentNode</var>, then <span data-x="concept-element-attributes-set-value">set</span>
61923-
the <code data-x="attr-details-open">open</code> attribute on <var>currentNode</var> to the
61924-
empty string.</p></li>
61925-
</ol>
61926-
</li>
61927-
61928-
<li><p>Otherwise, set <var>currentNode</var> to the parent node of
61929-
<var>currentNode</var> within the <span>flat tree</span>.</p></li>
61930-
</ol>
61931-
</li>
61932-
</ol>
61933-
6193461905
<div class="example">
6193561906

6193661907
<p>The following example shows the <code>details</code> element being used to hide technical
@@ -80071,8 +80042,7 @@ END:VCARD</pre>
8007180042
data-x="navigate-fragid">fragment navigation</span>. When these features attempt to scroll to a
8007280043
target which is in the element's subtree, the user agent will remove the <code
8007380044
data-x="attr-hidden">hidden</code> attribute in order to reveal the content before scrolling to
80074-
it by running the <span>ancestor hidden-until-found revealing algorithm</span> on the target
80075-
node.</p>
80045+
it by running the <span>ancestor revealing algorithm</span> on the target node.</p>
8007680046

8007780047
<div w-nodev>
8007880048

@@ -80227,30 +80197,80 @@ END:VCARD</pre>
8022780197
string.</p></li>
8022880198
</ol>
8022980199

80230-
<p>The <dfn>ancestor hidden-until-found revealing algorithm</dfn> is to run the following steps on
80231-
<var>currentNode</var>:</p>
80200+
<p>An <dfn>ancestor reveal pair</dfn> is a <span>tuple</span> consisting of a <dfn
80201+
data-x="ancestor-reveal-pair-node">node</dfn> and a <dfn
80202+
data-x="ancestor-reveal-pair-string">string</dfn>.</p>
80203+
80204+
<p>The <dfn>ancestor revealing algorithm</dfn> given a node <var>target</var> is:</p>
8023280205

8023380206
<ol>
80207+
<li><p>Let <var>ancestorsToReveal</var> be « ».</p></li>
80208+
80209+
<li><p>Let <var>ancestor</var> be <var>target</var>.</p></li>
80210+
80211+
<li>
80212+
<p>While <var>ancestor</var> has a parent node within the <span>flat tree</span>:</p>
80213+
80214+
<ol>
80215+
<li><p>If <var>ancestor</var> has a <code data-x="attr-hidden">hidden</code> attribute in the
80216+
<span data-x="attr-hidden-until-found-state">Hidden Until Found</span> state, then <span
80217+
data-x="list append">append</span> (<var>ancestor</var>, "<code data-x="">until-found</code>")
80218+
to <var>ancestorsToReveal</var>.</p></li>
80219+
80220+
<li><p>If <var>ancestor</var> is slotted into the second slot of a <code>details</code>
80221+
element which does not have an <code data-x="attr-details-open">open</code> attribute, then
80222+
<span data-x="list append">append</span> (<var>ancestor</var>'s parent node, "<code
80223+
data-x="">details</code>") to <var>ancestorsToReveal</var>.</p></li>
80224+
80225+
<li><p>Set <var>ancestor</var> to the parent node of <var>ancestor</var> within the
80226+
<span>flat tree</span>.</p></li>
80227+
</ol>
80228+
</li>
80229+
8023480230
<li>
80235-
<p>While <var>currentNode</var> has a parent node within the <span>flat tree</span>:</p>
80231+
<p>For each (<var>ancestorToReveal</var>, <var>revealType</var>) of
80232+
<var>ancestorsToReveal</var>:</p>
8023680233

8023780234
<ol>
80235+
<li><p>If <var>ancestorToReveal</var> is not <span>connected</span>, then return.</p></li>
80236+
8023880237
<li>
80239-
<p>If <var>currentNode</var> has the <code data-x="attr-hidden">hidden</code> attribute in the
80240-
<span data-x="attr-hidden-until-found-state">Hidden Until Found</span> state, then:</p>
80238+
<p>If <var>revealType</var> is "<code data-x="">until-found</code>":</p>
8024180239

8024280240
<ol>
80241+
<li><p>If <var>ancestorToReveal</var>'s <code data-x="attr-hidden">hidden</code> attribute is
80242+
not in the <span data-x="attr-hidden-until-found-state">Hidden Until Found</span> state, then
80243+
return.</p></li>
80244+
8024380245
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
80244-
data-x="event-beforematch">beforematch</code> at <var>currentNode</var> with the <code
80246+
data-x="event-beforematch">beforematch</code> at <var>ancestorToReveal</var> with the <code
8024580247
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>
8024680248

80249+
<li><p>If <var>ancestorToReveal</var> is not <span>connected</span>, then return.</p></li>
80250+
80251+
<li><p>If <var>ancestorToReveal</var>'s <code data-x="attr-hidden">hidden</code> attribute is
80252+
not in the <span data-x="attr-hidden-until-found-state">Hidden Until Found</span> state, then
80253+
return.</p></li>
80254+
8024780255
<li><p>Remove the <code data-x="attr-hidden">hidden</code> attribute from
80248-
<var>currentNode</var>.</p></li>
80256+
<var>ancestorToReveal</var>.</p></li>
8024980257
</ol>
80250-
</li>
80258+
<li>
8025180259

80252-
<li><p>Set <var>currentNode</var> to the parent node of <var>currentNode</var> within the
80253-
<span>flat tree</span>.</p></li>
80260+
<li>
80261+
<p>Otherwise:</p>
80262+
80263+
<ol>
80264+
<li><p><span>Assert</span>: <var>revealType</var> is "<code
80265+
data-x="">details</code>".</p></li>
80266+
80267+
<li><p>If <var>ancestorToReveal</var> has an <code data-x="attr-details-open">open</code>
80268+
attribute, then return.</p></li>
80269+
80270+
<li><p>Set <var>ancestorToReveal</var>'s <code data-x="attr-details-open">open</code>
80271+
attribute to the empty string.</p></li>
80272+
</ol>
80273+
</li>
8025480274
</ol>
8025580275
</li>
8025680276
</ol>
@@ -84122,15 +84142,8 @@ body { display:none }
8412284142
match</span>.</p></li>
8412384143

8412484144
<li><p><span>Queue a global task</span> on the <span>user interaction task source</span> given
84125-
<var>node</var>'s <span>relevant global object</span> to run the following steps:</p>
84126-
84127-
<ol>
84128-
<li><p>Run the <span>ancestor details revealing algorithm</span> on <var>node</var>.</p></li>
84129-
84130-
<li><p>Run the <span>ancestor hidden-until-found revealing algorithm</span> on
84131-
<var>node</var>.</p></li>
84132-
</ol>
84133-
</li>
84145+
<var>node</var>'s <span>relevant global object</span> to run the <span>ancestor revealing
84146+
algorithm</span> on <var>node</var>.</p></li>
8413484147
</ol>
8413584148

8413684149
<p class="warning">
@@ -106399,10 +106412,7 @@ location.href = '#foo';</code></pre>
106399106412

106400106413
<li><p>Set <var>document</var>'s <span>target element</span> to <var>target</var>.</p></li>
106401106414

106402-
<li><p>Run the <span>ancestor details revealing algorithm</span> on <var>target</var>.</p></li>
106403-
106404-
<li><p>Run the <span>ancestor hidden-until-found revealing algorithm</span> on
106405-
<var>target</var>.</p></li>
106415+
<li><p>Run the <span>ancestor revealing algorithm</span> on <var>target</var>.</p></li>
106406106416

106407106417
<li><p><span data-x="scroll a target into view">Scroll <var>target</var> into view</span>,
106408106418
with <i>behavior</i> set to "auto", <i>block</i> set to "start", and <i>inline</i>

0 commit comments

Comments
 (0)