Skip to content

Commit

Permalink
Make dashes in comments no longer be parse errors
Browse files Browse the repository at this point in the history
The spec disallowed dashes in comments in order to have conformance
checkers point out the problem for pre-2006 Firefox that implemented
SGML-style comment parsing, and to match the syntax requirements in
HTML4 and XML. These are no longer relevant and instead people are
getting unhelpful error messages when validating for markup like:

</div><!-- end .foo-bar--baz -->

* A comment that ends with a dash is now allowed: <!-- --->
* A comment that contains -- is also allowed: <!-- -- -->
* A comment that contains --! is also allowed: <!-- --! -->
* The following are still parse errors: <!-->, <!--->, <!-- --!>

Fixes #1351.

Also remove obsolete comments in the spec's source about rewinding
when hitting EOF (see #1058).
  • Loading branch information
zcorpan committed May 31, 2016
1 parent 9fd2c1c commit a0326a1
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -1497,10 +1497,11 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
<dd>

<p>When a user agent based on XML is connected to an HTML parser, it is possible that certain
invariants that XML enforces, such as comments never containing two consecutive hyphens, will be
violated by an HTML file. Handling this can require that the parser coerce the HTML DOM into an
XML-compatible infoset. Most syntax constructs that require such handling are considered
invalid.</p>
invariants that XML enforces, such as element or attribute names never contain multiple colons,
will be violated by an HTML file. Handling this can require that the parser coerce the HTML DOM
into an XML-compatible infoset. Most syntax constructs that require such handling are considered
invalid. (Comments containing two consecutive hyphens, or ending with a hyphen, are exceptions
that are allowed in the HTML syntax.)</p>

</dd>

Expand Down Expand Up @@ -98256,12 +98257,11 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {
<p><dfn data-x="syntax-comments">Comments</dfn> must start with the four character sequence U+003C
LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS (<code
data-x="">&lt;!--</code>). Following this sequence, the comment may have <span
data-x="syntax-text">text</span>, with the additional restriction that the text must not start with
a single U+003E GREATER-THAN SIGN character (&gt;), nor start with a U+002D HYPHEN-MINUS character
(-) followed by a U+003E GREATER-THAN SIGN (&gt;) character, nor contain two consecutive U+002D
HYPHEN-MINUS characters (<code data-x="">--</code>), nor end with a U+002D HYPHEN-MINUS character
(-). Finally, the comment must be ended by the three character sequence U+002D HYPHEN-MINUS,
U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN (<code data-x="">--&gt;</code>).</p>
data-x="syntax-text">text</span>, with the additional restriction that the text must not start
with a single U+003E GREATER-THAN SIGN character (&gt;), nor start with a U+002D HYPHEN-MINUS
character (-) followed by a U+003E GREATER-THAN SIGN (&gt;) character. Finally, the comment must
be ended by the three character sequence U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E
GREATER-THAN SIGN (<code data-x="">--&gt;</code>).</p>


<!--HTMLPARSER-->
Expand Down Expand Up @@ -101166,7 +101166,6 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {

<dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
<dd><span>Parse error</span>. Switch to the <span>data state</span>. Emit the comment token.</dd>
<!-- see comment in comment end state -->

<dt>EOF</dt>
<dd><span>Parse error</span>. Emit the comment token. <span>Reconsume</span> in the <span>data
Expand Down Expand Up @@ -101197,7 +101196,7 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {

<dt>EOF</dt>
<dd><span>Parse error</span>. Emit the comment token. <span>Reconsume</span> in the <span>data
state</span>.</dd> <!-- see comment in comment end state -->
state</span>.</dd>

<dt>Anything else</dt>
<dd>Append a U+002D HYPHEN-MINUS character (-) and the <span>current input character</span> to
Expand All @@ -101221,7 +101220,7 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {

<dt>EOF</dt>
<dd><span>Parse error</span>. Switch to the <span>data state</span>. Emit the comment token.
Reconsume the EOF character.</dd> <!-- see comment in comment end state -->
Reconsume the EOF character.</dd>

<dt>Anything else</dt>
<dd>Append the <span>current input character</span> to the comment token's data.</dd>
Expand All @@ -101244,7 +101243,7 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {

<dt>EOF</dt>
<dd><span>Parse error</span>. Switch to the <span>data state</span>. Emit the comment token.
Reconsume the EOF character.</dd> <!-- see comment in comment end state -->
Reconsume the EOF character.</dd>

<dt>Anything else</dt>
<dd>Append a U+002D HYPHEN-MINUS character (-) and the <span>current input character</span> to
Expand All @@ -101268,22 +101267,18 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {
state</span>.</dd>

<dt>U+0021 EXCLAMATION MARK (!)</dt>
<dd><span>Parse error</span>. Switch to the <span>comment end bang state</span>.</dd>
<dd>Switch to the <span>comment end bang state</span>.</dd>

<dt>U+002D HYPHEN-MINUS (-)</dt>
<dd><span>Parse error</span>. Append a U+002D HYPHEN-MINUS character (-) to the comment token's
data.</dd>
<dd>Append a U+002D HYPHEN-MINUS character (-) to the comment token's data.</dd>

<dt>EOF</dt>
<dd><span>Parse error</span>. Emit the comment token. <span>Reconsume</span> in the <span>data
state</span>.</dd> <!-- For security reasons: otherwise, hostile user could put a
<script> in a comment e.g. in a blog comment and then DOS the server so that the end tag isn't
read, and then the commented <script> tag would be treated as live code -->
state</span>.</dd>

<dt>Anything else</dt>
<dd><span>Parse error</span>. Append two U+002D HYPHEN-MINUS characters (-) and the <span>current
input character</span> to the comment token's data. Switch to the <span>comment
state</span>.</dd>
<dd>Append two U+002D HYPHEN-MINUS characters (-) and the <span>current input character</span> to
the comment token's data. Switch to the <span>comment state</span>.</dd>

</dl>

Expand All @@ -101299,7 +101294,7 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {
the comment token's data. Switch to the <span>comment end dash state</span>.</dd>

<dt>U+003E GREATER-THAN SIGN (&gt;)</dt>
<dd>Switch to the <span>data state</span>. Emit the comment token.</dd>
<dd><span>Parse error</span>. Switch to the <span>data state</span>. Emit the comment token.</dd>

<dt>U+0000 NULL</dt>
<dd><span>Parse error</span>. Append two U+002D HYPHEN-MINUS characters (-), a U+0021 EXCLAMATION
Expand All @@ -101308,7 +101303,7 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {

<dt>EOF</dt>
<dd><span>Parse error</span>. Emit the comment token. <span>Reconsume</span> in the <span>data
state</span>.</dd> <!-- see comment in comment end state -->
state</span>.</dd>

<dt>Anything else</dt>
<dd>Append two U+002D HYPHEN-MINUS characters (-), a U+0021 EXCLAMATION MARK character (!), and
Expand Down

0 comments on commit a0326a1

Please sign in to comment.