Skip to content

Commit b9c5dee

Browse files
authored
Allow <hr> to be used inside <select> as a separator
This is a long-standing WebKit feature that regressed as part of the standardized HTML parser effort. This suggests bringing it back with optional semantics, but a mandatory HTML parser change. The HTML parser change is not expected to be significant for existing content or XSS. When the feature is correctly used it will also not hurt HTML parsers that have not yet incorporated the change. I.e., it should be fully backwards compatible. Tests: html5lib/html5lib-tests#167. Fixes #3410.
1 parent b6d8428 commit b9c5dee

File tree

1 file changed

+52
-13
lines changed

1 file changed

+52
-13
lines changed

source

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19364,6 +19364,7 @@ and is further discussed below.&lt;/div></code></pre>
1936419364
<dd><span>Flow content</span>.</dd>
1936519365
<dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt>
1936619366
<dd>Where <span>flow content</span> is expected.</dd>
19367+
<dd>As a child of a <code>select</code> element.</dd>
1936719368
<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
1936819369
<dd><span data-x="concept-content-nothing">Nothing</span>.</dd>
1936919370
<dt><span data-x="concept-element-attributes">Content attributes</span>:</dt>
@@ -19385,8 +19386,9 @@ interface <dfn interface>HTMLHRElement</dfn> : <span>HTMLElement</span> {
1938519386
</dl>
1938619387

1938719388
<p>The <code>hr</code> element <span>represents</span> a <span>paragraph</span>-level thematic
19388-
break, e.g. a scene change in a story, or a transition to another topic within a section of a
19389-
reference book.</p>
19389+
break, e.g., a scene change in a story, or a transition to another topic within a section of a
19390+
reference book; alternatively, it represents a separator between a set of options of a
19391+
<code>select</code> element.</p>
1939019392

1939119393
<div class="example">
1939219394

@@ -52319,7 +52321,7 @@ interface <dfn interface>HTMLButtonElement</dfn> : <span>HTMLElement</span> {
5231952321
<dt><span data-x="concept-element-contexts">Contexts in which this element can be used</span>:</dt>
5232052322
<dd>Where <span>phrasing content</span> is expected.</dd>
5232152323
<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
52322-
<dd>Zero or more <code>option</code>, <code>optgroup</code>, and <span data-x="script-supporting elements">script-supporting</span> elements.</dd>
52324+
<dd>Zero or more <code>option</code>, <code>optgroup</code>, <code>hr</code>, and <span data-x="script-supporting elements">script-supporting</span> elements.</dd>
5232352325
<dt><span data-x="concept-element-attributes">Content attributes</span>:</dt>
5232452326
<dd><span>Global attributes</span></dd>
5232552327
<dd><code data-x="attr-fe-autocomplete">autocomplete</code></dd>
@@ -52873,6 +52875,19 @@ interface <dfn interface>HTMLSelectElement</dfn> : <span>HTMLElement</span> {
5287352875

5287452876
</div>
5287552877

52878+
<div class="example">
52879+
<p>Occasionally it can be useful to have a separator:
52880+
52881+
<pre><code class="html">&lt;label>
52882+
Select the song to play next:
52883+
&lt;select required name="next">
52884+
&lt;option value="sr">Random
52885+
&lt;hr>
52886+
&lt;option value="s1">It Sucks to Be Me (Reprise)
52887+
&lt;option value="s2">There is Life Outside Your Apartment
52888+
&hellip;</code></pre>
52889+
</div>
52890+
5287652891

5287752892

5287852893
<h4>The <dfn element><code>datalist</code></dfn> element</h4>
@@ -112874,10 +112889,11 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {
112874112889
below can handle the non-<select> case if we ever allow it) -->
112875112890
<p>An <code>optgroup</code> element's <span data-x="syntax-end-tag">end tag</span> may be omitted
112876112891
if the <code>optgroup</code> element <!--has an ancestor <code>select</code> element and--> is
112877-
immediately followed by another <code>optgroup</code> element, or if <!--all of the elements that
112878-
are ancestors of the <code>optgroup</code> element, up to and including the first ancestor element
112879-
that is not an <code>optgroup</code> element, have no more content--> there is no more content in
112880-
the parent element.</p>
112892+
immediately followed by another <code>optgroup</code> element, if it is immediately followed by an
112893+
<code>hr</code> element, or if <!--all of the elements that are ancestors of the
112894+
<code>optgroup</code> element, up to and including the first ancestor element that is not an
112895+
<code>optgroup</code> element, have no more content--> there is no more content in the parent
112896+
element.</p>
112881112897
<!-- so e.g. the max number of </optgroup>s are omitted here:
112882112898
<select><optgroup></select>
112883112899
<p id=x><optgroup></optgroup>x</p>
@@ -112888,9 +112904,9 @@ dictionary <dfn dictionary>StorageEventInit</dfn> : <span>EventInit</span> {
112888112904

112889112905
<!-- </option> -->
112890112906
<p>An <code>option</code> element's <span data-x="syntax-end-tag">end tag</span> may be omitted if
112891-
the <code>option</code> element is immediately followed by another <code>option</code> element, or
112892-
if it is immediately followed by an <code>optgroup</code> element, or if there is no more content
112893-
in the parent element.</p>
112907+
the <code>option</code> element is immediately followed by another <code>option</code> element, if
112908+
it is immediately followed by an <code>optgroup</code> element, if it is immediately followed by
112909+
an <code>hr</code> element, or if there is no more content in the parent element.</p>
112894112910

112895112911
<!-- <colgroup> -->
112896112912
<p>A <code>colgroup</code> element's <span data-x="syntax-start-tag">start tag</span> may be
@@ -121080,6 +121096,25 @@ document.body.appendChild(text);
121080121096
<p><span>Insert an HTML element</span> for the token.</p>
121081121097
</dd>
121082121098

121099+
<dt>A start tag whose tag name is "hr"</dt>
121100+
<dd>
121101+
<!-- fake </option> (maybe) -->
121102+
<p>If the <span>current node</span> is an <code>option</code> element, pop that node from the
121103+
<span>stack of open elements</span>.</p>
121104+
<!-- end of fake </option> -->
121105+
121106+
<!-- fake </optgroup> (maybe) -->
121107+
<p>If the <span>current node</span> is an <code>optgroup</code> element, pop that node from the
121108+
<span>stack of open elements</span>.</p>
121109+
<!-- end of fake </optgroup> -->
121110+
121111+
<p><span>Insert an HTML element</span> for the token. Immediately pop the <span>current
121112+
node</span> off the <span>stack of open elements</span>.</p>
121113+
121114+
<p><span data-x="acknowledge self-closing flag">Acknowledge the token's <i data-x="self-closing
121115+
flag">self-closing flag</i></span>, if it is set.</p>
121116+
</dd>
121117+
121083121118
<dt>An end tag whose tag name is "optgroup"</dt>
121084121119
<dd>
121085121120
<!-- fake </option> (maybe) -->
@@ -125976,6 +126011,9 @@ progress { appearance: auto; }</code></pre>
125976126011
data-x="concept-option-label">label</span>, indented under its <code>optgroup</code> element if it
125977126012
has one.</p>
125978126013

126014+
<p>Each sequence of one or more child <code>hr</code> element siblings may be rendered as a single
126015+
separator.</p>
126016+
125979126017
<p>The <dfn>width of the <code>select</code>'s labels</dfn> is the wider of the width necessary to
125980126018
render the widest <code>optgroup</code>, and the width necessary to render the widest
125981126019
<code>option</code> element in the element's <span data-x="concept-select-option-list">list of
@@ -134187,16 +134225,16 @@ INSERT INTERFACES HERE
134187134225
Dean Edridge,
134188134226
Dean Edwards,
134189134227
Dean Jackson,
134190-
Debanjana Sarkar <!-- debanjana-a11y on GitHub -->,
134228+
Debanjana Sarkar, <!-- debanjana-a11y on GitHub -->
134191134229
Debi Orton,
134192-
Delan Azabani<!-- delan on GitHub -->,
134230+
Delan Azabani, <!-- delan on GitHub -->
134193134231
Derek Featherstone,
134194134232
Derek Guenther,
134195134233
Devarshi Pant,
134196134234
Devdatta,
134197134235
Devin Rousso,
134198134236
Diego Ferreiro Val,
134199-
Diego Gonz&aacute;lez Z&uacute;&ntilde;iga <!-- diekus on GitHub -->,
134237+
Diego Gonz&aacute;lez Z&uacute;&ntilde;iga, <!-- diekus on GitHub -->
134200134238
Diego Ponce de León,
134201134239
Dimitri Glazkov,
134202134240
Dimitry Golubovsky,
@@ -134240,6 +134278,7 @@ INSERT INTERFACES HERE
134240134278
Eric Portis,
134241134279
Eric Rescorla,
134242134280
Eric Semling,
134281+
Eric Shepherd, <!-- a2sheppy on GitHub -->
134243134282
Eric Willigers,
134244134283
Erik Arvidsson,
134245134284
Erik Charlebois,

0 commit comments

Comments
 (0)