[whatwg/dom] A way for createAttribute() to bypass XML Name validation in HTML documents (#769)

`createAttribute(localName)` and other attribute creating methods (`setAttribute` and such) require attribute name to be a valid XML Name, and throw otherwise.

However, the HTML parser is less restrictive in attribute names, allowing HTML documents to have some attribute names that are illegal in XML.

Whenever it is needed to programmatically create an attribute with a name that is allowed in HTML but illegal in XML, this is possible through the parser, but not with DOM attribute creating methods, it seems.

```javascript
document.createAttribute('impo$$ible'); // throws

const createHTMLAttribute = name =>
  document.importNode(
    new DOMParser().parseFromString(`<html ${name}>`, 'text/html')
      .documentElement.getAttributeNode(name)
  );

createHTMLAttribute('impo$$ible'); // 'impo$$ible=""'
```

Could `createAttribute` (and maybe `setAttribute` and friends) be somehow allowed to create such attributes in HTML documents?

-- 
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/769

Received on Wednesday, 26 June 2019 09:45:27 UTC