Reputation: 22974
An unknown named character reference like &this
gives an ambiguous ampersand error.
<textarea>
&this
</textarea>
What did i understand wrongly here? Any suggestions?
Upvotes: 1
Views: 166
Reputation: 724252
You seem to expect the page to not render and the browser to display an error of sorts. That's not how HTML works. The browser simply does what it thinks (or what the HTML5 spec says) it should do with the invalid markup and continue on its merry way.
In this case, an ambiguous ampersand is treated literally by the browser. The parser still encounters a parse error, as described here, but the browser recovers from this error and continues on its merry way. The markup will simply not validate.
If you were expecting an error condition, you might be thinking of XHTML. A named character reference that does not correspond to a valid entity will indeed cause an irrecoverable error in XHTML.
Upvotes: 1
Reputation: 1524
You did nothing wrong, the browser has determined that you are attempting to place an ampersand in the textarea
and has escaped it for you (to &
). You can verify this by viewing the source (inspect element
) and then editing the textarea as html
.
Thus preventing you from invoking the underlying error, or going into a nasty gotcha, as described in the specification.
It should also be noted that the reason for the textarea doing this is mostly due to the fact that data will be transferred under application/x-www-form-urlencoded
(or multipart/form-data
) and not html, thus requiring it to escape entities to be valid.
Further reading at a lower level on #PCDATA
/ CDATA
and Character References
can be found here:
http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.3.3.1
http://www.w3.org/TR/html4/charset.html#entities
http://www.w3.org/TR/html5/syntax.html#character-references
http://www.w3.org/TR/html5/syntax.html#cdata-sections
Upvotes: 1
Reputation: 574
What you're reading is the specification of when a element is valid in HTML5. HTML is an interpreted language (it's not compiled like Java or C), so if you have a problem with the specification in your HTML file you won't see an error message when loaded by a browser. To validate an HTML file you must use: http://validator.w3.org/.
Upvotes: 0