createElement restrictions on names do not match innerHTML-parseable names

>From http://dom.spec.whatwg.org/#dom-document-createelement:

> If localName does not match the Name production, throw an "InvalidCharacterError" exception and terminate these steps.

The "Name" production links to http://www.w3.org/TR/xml/#NT-Name, which says:

```
[4]   	NameStartChar	   ::=   	":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
[4a]   	NameChar	   ::=   	NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
[5]   	Name	   ::=   	NameStartChar (NameChar)*
```

And indeed, browsers will throw such an error. But they accept such element names when parsing HTML, e.g.

http://jsconsole.com/?document.body.innerHTML%3D%22%3Ca\0%20href%3D%27foo%27%3E%3Cb%3E%22%3Bdocument.body.children[0].tagName

http://jsconsole.com/?document.body.innerHTML%3D%22%3Ca\xD7%20href%3D%27foo%27%3E%3Cb%3E%22%3Bdocument.body.children[0].tagName

Is this mismatch intentional? Does it make sense?

In particular, this makes it impossible to explain the behavior of the parser in terms of JS, as we try to do in [jsdom](https://github.com/tmpvar/jsdom).

Received on Thursday, 25 July 2013 14:24:23 UTC