diff --git a/dom.bs b/dom.bs index 4f4a767a1..1643aad64 100644 --- a/dom.bs +++ b/dom.bs @@ -12,12 +12,12 @@ Indent: 1
 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
@@ -209,19 +209,59 @@ against a set, run these steps:
 added.
 
 
-

Namespaces

+

Name validation

-

To validate a qualifiedName, throw an -"{{InvalidCharacterError!!exception}}" {{DOMException}} if qualifiedName does not match -the QName production. +

A [=string=] is a valid namespace prefix if its [=string/length=] is at least 1 and it +does not contain [=ASCII whitespace=], U+0000 NULL, U+002F (/), or U+003E (>). -

To validate and extract a namespace and qualifiedName, -run these steps: +

A [=string=] is a valid attribute local name if its [=string/length=] is at least 1 +and it does not contain [=ASCII whitespace=], U+0000 NULL, U+002F (/), U+003D (=), or U+003E (>). + +

A [=string=] |name| is a valid element local name if the following steps return true:

    -
  1. If namespace is the empty string, then set it to null. +

  2. If |name|'s [=string/length=] is 0, then return false. -

  3. Validate qualifiedName. +

  4. +

    If |name|'s 0th [=code point=] is an [=ASCII alpha=], then: + +

      +
    1. If |name| contains [=ASCII whitespace=], U+0000 NULL, U+002F (/), or U+003E (>), then + return false. + +

    2. Return true. +

    + +
  5. If |name|'s 0th [=code point=] is not U+003A (:), U+005F (_), or in the range U+0080 + to U+10FFFF, inclusive, then return false. + +

  6. If |name|'s subsequent [=code points=], if any, are not [=ASCII alphas=], [=ASCII digits=], + U+002D (-), U+002E (.), U+003A (:), U+005F (_), or in the range U+0080 to U+10FFFF, inclusive, then + return false. + +

  7. Return true. +

+ +

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 (the branch where the first [=code point=] is an [=ASCII alpha=]), plus some additional +possibilities. For those additional possibilities, the ASCII range is restricted for historical +reasons, but beyond ASCII anything is allowed. + +

+

The following JavaScript-compatible regular expression is an implementation of the above + definition: + +

+  /^(?:[A-Za-z][^\0\t\n\f\r\u0020/>]*)|(?:[:_\u0080-\u{10FFFF}][A-Za-z0-9-.:_\u0080-\u{10FFFF}]*)$/u
+ 
+
+ +

To validate and extract a namespace and qualifiedName, given a +context: + +

    +
  1. If namespace is the empty string, then set it to null.

  2. Let prefix be null. @@ -230,6 +270,15 @@ run these steps:

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

  4. If prefix is not a [=valid namespace prefix=], then [=throw=] an + "{{InvalidCharacterError}}" {{DOMException}}. + +

  5. If context is "attribute" and localName is not a + [=valid attribute local name=], then [=throw=] an "{{InvalidCharacterError}}" {{DOMException}}. + +

  6. If context is "element" and localName is not a + [=valid element local name=], then [=throw=] an "{{InvalidCharacterError}}" {{DOMException}}. +

  7. If prefix is non-null and namespace is null, then throw a "{{NamespaceError!!exception}}" {{DOMException}}. @@ -5076,8 +5125,8 @@ method steps are to return the list of elements with class names classNa document is an HTML document or document's content type is "application/xhtml+xml"; otherwise null. -

    If localName does not match the Name production an - "{{InvalidCharacterError!!exception}}" {{DOMException}} will be thrown. +

    If localName is not a valid element local name an + "{{InvalidCharacterError}}" {{DOMException}} will be thrown.

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

    If qualifiedName does not match the QName production an - "{{InvalidCharacterError!!exception}}" {{DOMException}} will be thrown. +

    If qualifiedName is not a (possibly-prefixed) + valid element local name an "{{InvalidCharacterError}}" {{DOMException}} will be + thrown.

    If one of the following conditions is true a "{{NamespaceError!!exception}}" {{DOMException}} will be thrown: @@ -5135,8 +5185,7 @@ method steps are to return the list of elements with class names classNa node whose target is target and data is data. - If target does not match the - Name production an + If target does not match the [=XML/Name=] production an "{{InvalidCharacterError!!exception}}" {{DOMException}} will be thrown. If data contains "?>" an "{{InvalidCharacterError!!exception}}" {{DOMException}} will be thrown. @@ -5153,7 +5202,7 @@ method steps are to return the list of elements with class names classNa method steps are:

      -
    1. If localName does not match the Name production, then +

    2. If localName is not a valid element local name, then throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}.

    3. If this is an HTML document, then set localName to @@ -5179,7 +5228,8 @@ method steps are:

      1. Let namespace, prefix, and localName be the result of - passing namespace and qualifiedName to validate and extract. + [=validate and extract|validating and extracting=] namespace and + qualifiedName given "element".

      2. Let is be null. @@ -5210,7 +5260,7 @@ to return a new {{Text}} node whose data i and node document is this.

        No check is performed that data consists of -characters that match the Char production. +characters that match the Char production.

        The createCDATASection(data) method steps are: @@ -5231,7 +5281,7 @@ to return a new {{Comment}} node whose datanode document is this.

        No check is performed that data consists of -characters that match the Char production +characters that match the Char production or that it contains two adjacent hyphens or ends with a hyphen.

        The @@ -5240,8 +5290,7 @@ method steps are:

        1. If target does not match the - - Name production, + [=XML/Name=] production, then throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}.
        2. If data contains the string @@ -5258,7 +5307,7 @@ method steps are:

          No check is performed that target contains "xml" or ":", or that data contains characters that match the -Char production. +Char production.


          @@ -5359,8 +5408,8 @@ these steps: steps are:
            -
          1. If localName does not match the Name production in XML, - then throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}. +

          2. If localName is not a valid attribute local name, then + throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}.

          3. If this is an HTML document, then set localName to localName in ASCII lowercase. @@ -5375,7 +5424,8 @@ method steps are:
            1. Let namespace, prefix, and localName be the result of - passing namespace and qualifiedName to validate and extract. + [=validate and extract|validating and extracting=] namespace and + qualifiedName given "attribute".

            2. Return a new attribute whose namespace is namespace, namespace prefix is prefix, local name is @@ -5521,10 +5571,8 @@ interface DOMImplementation { Returns a doctype, with the given qualifiedName, publicId, and systemId. If qualifiedName does not - match the Name production, an - "{{InvalidCharacterError!!exception}}" {{DOMException}} is thrown, and if it does not match the - QName production, a - "{{NamespaceError!!exception}}" {{DOMException}} is thrown. + match the QName production, an + "{{InvalidCharacterError!!exception}}" {{DOMException}} is thrown.

              doc = document . {{Document/implementation}} . createDocument(namespace, qualifiedName [, doctype = null]) @@ -5557,7 +5605,8 @@ interface DOMImplementation { method steps are:
                -
              1. Validate qualifiedName. +

              2. If qualifiedName does not match the QName production, + then throw an "{{InvalidCharacterError}}" {{DOMException}}.

              3. Return a new doctype, with qualifiedName as its name, publicId as its public ID, and systemId @@ -5566,7 +5615,7 @@ method steps are:

              No check is performed that publicId code points match the -PubidChar production or that systemId does not contain both a +PubidChar production or that systemId does not contain both a '"' and a "'".

              The @@ -6573,8 +6622,14 @@ method steps are: method steps are:

                -
              1. If qualifiedName does not match the Name production in - XML, then throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}. +

              2. +

                If qualifiedName is not a valid attribute local name, then throw an + "{{InvalidCharacterError!!exception}}" {{DOMException}}. + +

                Despite the parameter naming, + qualifiedName is only used as a [=Attr/qualified name=] if an [=attribute=] already + exists with that qualified name. Otherwise, it is used as the [=Attr/local name=] of the new + attribute. We only need to validate it for the latter case.

              3. If this is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in @@ -6599,7 +6654,8 @@ method steps are:

                1. Let namespace, prefix, and localName be the result of - passing namespace and qualifiedName to validate and extract. + [=validate and extract|validating and extracting=] namespace and + qualifiedName given "element".

                2. Set an attribute value for this using localName, value, and also prefix and namespace. @@ -6632,8 +6688,12 @@ steps are: method steps are:

                    -
                  1. If qualifiedName does not match the Name production in - XML, then throw an "{{InvalidCharacterError!!exception}}" {{DOMException}}. +

                  2. +

                    If qualifiedName is not a valid attribute local name, then throw an + "{{InvalidCharacterError!!exception}}" {{DOMException}}. + +

                    See the discussion above about why + we validate it as a local name, instead of a qualified name.

                  3. If this is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in