Repository: whatwg/html

Issue #1257: Make &aaa; a parse error
Created: 2016-05-16T11:10:10Z
See #1220 (comment)
In particular, &aaa; or <p title="&ampersand;"> should be parse errors but are not right now because characters are only consumed so long as they match something in the named character references table, and then the temporary buffer is checked for a trailing ; (for the above examples it would contain &aa or &ampe, respectively).
In https://checker.html5.org/ it reports an error for these cases. It does not report an error for really long entities (like 1000 chars).
Possible fixes:


A new state that continues to consume (and append to the temporary buffer) alphanumerics when no match could be made, and that report a parse error on ';' and reconsume in character reference end state, and reconsume without parse error for anything else.
This means that the temporary buffer would need to be able to hold an arbitrary amount of characters, which seems bad...


Use new states that insert stuff in the right places (emit a char token or append to attribute value), and parse error on ;.


Like (1) but have a fixed length of characters to consume in the temporary buffer (i.e. like v.nu HTML parser).


Also need to update the note in the spec about &notit; in an attribute value.
@RReverser @sideshowbarker

Duplicate issue #2704: [Parser] Ambiguous ampersand is incorrectly handled in tokenizer
Created: 2017-05-22T21:57:14Z
This is how ambiguous ampersand is handled in the spec currently:

If the temporary buffer consists of a U+0026 AMPERSAND character (&) followed by a sequence of one or more ASCII alphanumerics and a U+003B SEMICOLON character (;), then this is a parse error.

(see https://html.spec.whatwg.org/multipage/syntax.html#named-character-reference-state).
The issue is that temporary buffer should contain only characters that match one of the character references:

Consume the maximum number of characters possible, with the consumed characters matching one of the identifiers in the first column of the named character references table (in a case-sensitive manner). Append each character to the temporary buffer when it's consumed.

Therefore, condition for the ambiguous ampersand will never be met: if temporary buffer contains characters and a semicolon then there was a match for a character reference, since there are no character references with a semicolon in the middle. Moreover, even if we'll solve issue with a trailing semicolon in the temporary buffer it will be insufficient to correctly report error for the ambiguous ampersand: we will only report errors for incomplete well-known character references.
The correct way to handle this will be introduction of the additional ambiguous ampersand state, to which we'll switch if no match was made. And in this state:

on ASCII alphanumeric: append character to the temporary buffer
on SEMICOLON: If the temporary buffer contains more than one character (i.e. at least one ASCII alphanumeric, first one is always AMPERSAND as per https://html.spec.whatwg.org/multipage/syntax.html#character-reference-state) then report a parse error. Reconsume in the character reference end state.
on anything else: reconsume in the character reference end state.

Closing comment (2017-05-24T15:23:43Z): I think this is a duplicate of #1257 , so closing this one.
It looks like we've come to the same conclusion, that this should be solved with a new state.