- From: C. Scott Ananian <notifications@github.com>
- Date: Fri, 27 Jul 2018 16:07:58 +0000 (UTC)
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/671@github.com>
The spec is not clear about the valid arguments to `Document#createElementNS()`. It states: > To validate a qualifiedName, throw an "InvalidCharacterError" DOMException if qualifiedName does not match the Name or QName production. But this doesn't explicitly clarify what happens when the `qualifiedName` matches `Name` but not `QName`, for instance the string `foo:bar:bat`. Since `QName` is defined in term of `Name` anyway, I believe this would be more clearly stated as just `...if qualifiedName does not match the QName production` (eliminating the reference to `Name`). However, this would change the errors thrown in some corner cases. According to [the test suite](https://github.com/cscott/web-platform-tests/blob/master/dom/nodes/Document-createElementNS.js), calling `document.createElementNS(null, ":foo")` ought to throw a `NAMESPACE_ERR` (line 24), but `:foo` doesn't match `QName` (prefix must be at least one character in the production), so it ought to throw an `INVALID_CHARACTER_ERROR`. (This assumes that `prefix` will be set to the empty string on line 5 which will trigger the exception on line 6 because the empty string is "non-null".) On the other hand, `document.createElementNS("http://example.com", ":foo")` ought to throw a `NAMESPACE_ERR` (test case ine 56) yet there is no spec language to justify this: if it failed the "validate qualifiedName" test it ought to throw a INVALID_CHARACTER_ERROR, and steps 5 and 6 state: >5. If qualifiedName contains a ":" (U+003E), then split the string on it and set prefix to the part before and localName to the part after. >6. If prefix is non-null and namespace is null, then throw a "NamespaceError" DOMException. At this point the namespace is non-null and the prefix is the empty string. There is no language triggering a NamespaceError. See also https://github.com/web-platform-tests/wpt/pull/12202 which covers some other issues with the test suite for `createElementNS()`, so fixing the test suite might be reasonable. For best compliance with the existing test suite, the "validate a qualifiedName" test could be written as: >To validate a qualifiedName, throw an "InvalidCharacterError" DOMException if qualifiedName does not match the Name production. Otherwise, throw a "NamespaceError" DOMException if qualifiedName does not match the QName production. That would be my recommended fix. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/671
Received on Friday, 27 July 2018 16:08:24 UTC