Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more characters in element/attribute names and prefixes #1079

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
96 changes: 62 additions & 34 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Indent: 1

<pre class=anchors>
urlPrefix: https://www.w3.org/TR/xml/#NT-
type: type
text: Name; url: Name
type: dfn
text: Name; url: Name; for: XML
text: Char; url: Char
text: PubidChar; url: PubidChar
urlPrefix: https://www.w3.org/TR/xml-names/#NT-
type: type
type: dfn
text: QName; url: QName
url: https://w3c.github.io/DOM-Parsing/#dfn-createcontextualfragment-fragment
type: method; text: createContextualFragment(); for: Range
Expand Down Expand Up @@ -209,27 +209,56 @@ against a <var>set</var>, run these steps:
added.


<h3 id=namespaces>Namespaces</h3>
<h3 id=name-validation oldids=namespaces>Name validation</h3>

<p>To <dfn export>validate</dfn> a <var>qualifiedName</var>, <a>throw</a> an
"{{InvalidCharacterError!!exception}}" {{DOMException}} if <var>qualifiedName</var> does not match
the <code><a type>QName</a></code> production.
A [=string=] |string| is a <dfn>valid base-case DOM API name</dfn> if it does not contain
[=ASCII whitespace=], U+0000 NULL, U+002F (/), or U+003E (>).
domenic marked this conversation as resolved.
Show resolved Hide resolved

<p>To <dfn export>validate and extract</dfn> a <var>namespace</var> and <var>qualifiedName</var>,
run these steps:
<p class="note">This concept is used to validate [=attribute=] [=Attr/local names=] and
[=Attr/qualified names=], as well as both [=Element/namespace prefix|element=] and
[=Attr/namespace prefix|attribute=] namespace prefixes, in the cases where elements and attributes
are constructed with DOM APIs. Note that the prefixes additionally cannot contain U+003A (:) by
construction since they always result from the [=validate and extract=] algorithm.

A [=string=] |string| is a <dfn>valid DOM API element local name</dfn> if it matches the following
<code>[=DOMAPIElementName=]</code>
<a href="https://www.w3.org/TR/xml/#sec-notation">EBNF production</a>. The notation used here is as
defined in <cite>XML</cite>. [[!XML]]

<pre class=lang-ebnf>
<dfn>DOMAPIElementName</dfn> ::= <a>HTMLParserCompatibleName</a> | <a>BeyondHTMLParserName</a>

<dfn>HTMLParserCompatibleName</dfn> ::= [a-zA-Z] [^#x00#x09#x0A#0xCx0D#x20/>]*

<dfn>BeyondHTMLParserName</dfn> ::= <a>BeyondHTMLParserNameStartChar</a> (<a>BeyondHTMLParserNameChar</a>)*
<dfn>BeyondHTMLParserNameStartChar</dfn> ::= ":" | "_" | [#x80-#x10FFFF]
<dfn>BeyondHTMLParserNameChar</dfn> ::= <a>BeyondHTMLParserNameStartChar</a> | [a-zA-Z] | "-" | "." | [0-9]
</pre>

<p class="note">This concept is used to validate [=/element=] [=Element/local names=], when
constructed by DOM APIs. The intention is to allow any name that is possible to construct using the
HTML parser, plus some additional possibilities. For those additional possibilities, the ASCII range
is restricted for historical reasons, but beyond ASCII anything is allowed.


<p>To <dfn>validate and extract</dfn> a <var>namespace</var> and <var>qualifiedName</var>:

<ol>
<li><p>If <var>namespace</var> is the empty string, then set it to null.

<li><p><a>Validate</a> <var>qualifiedName</var>.

<li><p>Let <var>prefix</var> be null.

<li><p>Let <var>localName</var> be <var>qualifiedName</var>.

<li><p>If <var>qualifiedName</var> contains a U+003A (:), then <a>strictly split</a> the string on
it and set <var>prefix</var> to the part before and <var>localName</var> to the part after.

<li><p>If <var>prefix</var> is not a [=valid base-case DOM API name=], then [=throw=] an
{{InvalidCharacterError}}" {{DOMException}}.

<li><p>If <var>localName</var> is not a [=valid DOM API element local name=], then [=throw=] an
"{{InvalidCharacterError}}" {{DOMException}}.

<li><p>If <var>prefix</var> is non-null and <var>namespace</var> is null, then <a>throw</a> a
"{{NamespaceError!!exception}}" {{DOMException}}.

Expand Down Expand Up @@ -5076,8 +5105,8 @@ method steps are to return the <a>list of elements with class names <var>classNa
<var>document</var> is an <a>HTML document</a> or <var>document</var>'s
<a for=Document>content type</a> is "<code>application/xhtml+xml</code>"; otherwise null.

<p>If <var>localName</var> does not match the <code><a type>Name</a></code> production an
"{{InvalidCharacterError!!exception}}" {{DOMException}} will be thrown.
<p>If <var>localName</var> is not a <a>valid DOM API element local name</a> an
"{{InvalidCharacterError}}" {{DOMException}} will be thrown.

<p>When supplied, <var>options</var>'s {{ElementCreationOptions/is}} can be used to create a
<a>customized built-in element</a>.
Expand All @@ -5090,8 +5119,9 @@ method steps are to return the <a>list of elements with class names <var>classNa
<var>qualifiedName</var> or null. Its <a for=Element>local name</a> will be everything after
U+003A (:) in <var>qualifiedName</var> or <var>qualifiedName</var>.

<p>If <var>qualifiedName</var> does not match the <code><a type>QName</a></code> production an
"{{InvalidCharacterError!!exception}}" {{DOMException}} will be thrown.
<p>If <var>qualifiedName</var> is not a (possibly-prefixed)
<a>valid DOM API element local name</a> an "{{InvalidCharacterError}}" {{DOMException}} will be
thrown.

<p>If one of the following conditions is true a "{{NamespaceError!!exception}}" {{DOMException}}
will be thrown:
Expand Down Expand Up @@ -5135,8 +5165,7 @@ method steps are to return the <a>list of elements with class names <var>classNa
<a for=/>node</a> whose
<a for=ProcessingInstruction>target</a> is <var>target</var> and
<a for=CharacterData>data</a> is <var>data</var>.
If <var>target</var> does not match the
<code><a type>Name</a></code> production an
If <var>target</var> is not a <a>valid base-case DOM API name</a> an
"{{InvalidCharacterError!!exception}}" {{DOMException}} will be thrown.
If <var>data</var> contains "<code>?></code>" an
"{{InvalidCharacterError!!exception}}" {{DOMException}} will be thrown.
Expand All @@ -5153,7 +5182,7 @@ method steps are to return the <a>list of elements with class names <var>classNa
method steps are:

<ol>
<li><p>If <var>localName</var> does not match the <code><a type>Name</a></code> production, then
<li><p>If <var>localName</var> is not a <a>valid DOM API element local name</a>, then
<a>throw</a> an "{{InvalidCharacterError!!exception}}" {{DOMException}}.

<li><p>If <a>this</a> is an <a>HTML document</a>, then set <var>localName</var> to
Expand Down Expand Up @@ -5210,7 +5239,7 @@ to return a new {{Text}} <a for=/>node</a> whose <a for=CharacterData>data</a> i
and <a for=Node>node document</a> is <a>this</a>.

<p class=note>No check is performed that <var>data</var> consists of
characters that match the <code><a type>Char</a></code> production.
characters that match the <code><a>Char</a></code> production.

<p>The <dfn method for=Document><code>createCDATASection(<var>data</var>)</code></dfn> method steps
are:
Expand All @@ -5231,17 +5260,17 @@ to return a new {{Comment}} <a for=/>node</a> whose <a for=CharacterData>data</a
and <a for=Node>node document</a> is <a>this</a>.

<p class=note>No check is performed that <var>data</var> consists of
characters that match the <code><a type>Char</a></code> production
characters that match the <code><a>Char</a></code> production
or that it contains two adjacent hyphens or ends with a hyphen.

<p>The
<dfn method for=Document><code>createProcessingInstruction(<var>target</var>, <var>data</var>)</code></dfn>
method steps are:

<ol>
<li>If <var>target</var> does not match the
<li>If <var>target</var> is does not match the
<!--<code data-anolis-type>PITarget</code>-->
<code><a type>Name</a></code> production,
<code>[=XML/Name=]</code> production,
then <a>throw</a> an "{{InvalidCharacterError!!exception}}" {{DOMException}}. <!-- DOM3 does not check for "xml" -->
domenic marked this conversation as resolved.
Show resolved Hide resolved

<li>If <var>data</var> contains the string
Expand All @@ -5258,7 +5287,7 @@ method steps are:
<p class=note>No check is performed that <var>target</var> contains
"<code>xml</code>" or "<code>:</code>", or that
<var>data</var> contains characters that match the
<code><a type>Char</a></code> production.
<code><a>Char</a></code> production.

<hr>

Expand Down Expand Up @@ -5359,7 +5388,7 @@ these steps:
steps are:

<ol>
<li><p>If <var>localName</var> does not match the <code><a type>Name</a></code> production in XML,
<li><p>If <var>localName</var> is not a <a>valid base-case DOM API name</a>,
then <a>throw</a> an "{{InvalidCharacterError!!exception}}" {{DOMException}}.

<li>If <a>this</a> is an <a>HTML document</a>, then set <var>localName</var> to
Expand Down Expand Up @@ -5521,10 +5550,8 @@ interface DOMImplementation {
Returns a <a>doctype</a>, with the given
<var>qualifiedName</var>, <var>publicId</var>, and
<var>systemId</var>. If <var>qualifiedName</var> does not
match the <code><a type>Name</a></code> production, an
"{{InvalidCharacterError!!exception}}" {{DOMException}} is thrown, and if it does not match the
<code><a type>QName</a></code> production, a
"{{NamespaceError!!exception}}" {{DOMException}} is thrown.
match the <code><a>QName</a></code> production, an
"{{InvalidCharacterError!!exception}}" {{DOMException}} is thrown.

<dt><code><var>doc</var> = <var>document</var> . {{Document/implementation}} . <a method for=DOMImplementation lt=createDocument()>createDocument(<var>namespace</var>, <var>qualifiedName</var> [, <var>doctype</var> = null])</a></code>

Expand Down Expand Up @@ -5557,7 +5584,8 @@ interface DOMImplementation {
method steps are:

<ol>
<li><p><a>Validate</a> <var>qualifiedName</var>.
<li><p>If <var>qualifiedName</var> does not match the <code><a>QName</a></code> production,
then throw an "{{InvalidCharacterError}}" {{DOMException}}.

<li><p>Return a new <a>doctype</a>, with <var>qualifiedName</var> as its
<a for=DocumentType>name</a>, <var>publicId</var> as its <a>public ID</a>, and <var>systemId</var>
Expand All @@ -5566,7 +5594,7 @@ method steps are:
</ol>

<p class=note>No check is performed that <var>publicId</var> code points match the
<code><a type>PubidChar</a></code> production or that <var>systemId</var> does not contain both a
<code><a>PubidChar</a></code> production or that <var>systemId</var> does not contain both a
'<code>"</code>' and a "<code>'</code>".

<p>The
Expand Down Expand Up @@ -6573,8 +6601,8 @@ method steps are:
method steps are:

<ol>
<li><p>If <var>qualifiedName</var> does not match the <code><a type>Name</a></code> production in
XML, then <a>throw</a> an "{{InvalidCharacterError!!exception}}" {{DOMException}}.
<li><p>If <var>qualifiedName</var> is not a <a>valid base-case DOM API name</a>, then <a>throw</a>
an "{{InvalidCharacterError!!exception}}" {{DOMException}}.

<li><p>If <a>this</a> is in the <a>HTML namespace</a> and its <a for=Node>node document</a> is an
<a>HTML document</a>, then set <var>qualifiedName</var> to <var>qualifiedName</var> in
Expand Down Expand Up @@ -6632,8 +6660,8 @@ steps are:
method steps are:

<ol>
<li><p>If <var>qualifiedName</var> does not match the <code><a type>Name</a></code> production in
XML, then <a>throw</a> an "{{InvalidCharacterError!!exception}}" {{DOMException}}.
<li><p>If <var>qualifiedName</var> is not a <a>valid base-case DOM API name</a>, then <a>throw</a>
an "{{InvalidCharacterError!!exception}}" {{DOMException}}.

<li><p>If <a>this</a> is in the <a>HTML namespace</a> and its <a for=Node>node document</a> is an
<a>HTML document</a>, then set <var>qualifiedName</var> to <var>qualifiedName</var> in
Expand Down