Allow more characters when creating various nodes#1079
Conversation
annevk
left a comment
There was a problem hiding this comment.
Do we want to call out the = difference in a note? At least a comment would be good I think.
I'm not a big fan of adding "DOM API" to the naming. That makes more sense if this was defined outside of the DOM Standard itself. I think dropping it would still make everything work.
|
Discussed equals sign at HTML triage meeting. Conclusion: disallow it in attributes everywhere. (Even though the parser allows it in the first-character position.) |
|
I think this is ready for re-review. Potential issue: XML's definition of Char seems nonsensical (it excludes various Unicode characters below U+0020). And, its definition of the |
|
Refined to no longer use EBNF. |
annevk
left a comment
There was a problem hiding this comment.
This does not seem equivalent to the sorta-EBNF from before. In particular if the first code point is from BeyondHTMLParserName the second code point was more limited.
I'm not sure exactly what you mean. Recall that it's a union of both. The second+ code point is from HTMLParserCompatibleName, which had |
|
I don't think the EBNF allows for the second code point to be U+0001 when the first is (I didn't see "An equivalent EBNF is the following" initially and I don't think what it states is correct.) |
|
I see, I did not capture that this was a branching scenario depending on the behavior of the first code point. And you addressed what harms names like that might hypothetically cause in #849 (comment) . I'll revise. |
|
I think that is done. The other way I could write this is by looping over the characters individually, which is what a performant implementation would do (instead of using lots of O(n) "contains" operations). But I think this is relatively clear. (Edit: well, a performant implementation would be looping over code units, since that's JS's native string format... which feels ickier to spec.) |
annevk
left a comment
There was a problem hiding this comment.
Thanks, this looks accurate to me.
|
OK, this (and whatwg/html#7991) is just waiting on someone to write web platform tests. Then we can close a ~5 year old recurring pain point on the web platform! For fun, these are all the references to this I can find:
I suspect there are more GitHub issues from earlier, because why would I have posted #449 if not because of some other issue someone filed? But I couldn't find them. |
|
@josepharhar would you be interested in finishing this? |
|
Yes, I have started a WPT here: web-platform-tests/wpt#38503 |
|
\o/ I suspect that once you implement this and do a try run you'll find a lot of existing WPT tests that can be adjusted. There's probably no need for a new file, but maybe. |
|
Any progress on this? |
|
Not recently, I have unfortunately been focused on other stuff. |
https://bugs.webkit.org/show_bug.cgi?id=241419 Reviewed by NOBODY (OOPS!). Implement relaxed name-validation rules per whatwg/dom#1079, whatwg/html#7991, and whatwg/html#11453. This aligns DOM API name behavior with HTML parser behavior — which has always allowed a wider range of characters in element and attribute names. New validation functions in NameValidation.h/cpp: - isValidElementName(): For createElement — allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - isValidAttributeName(): For setAttribute/toggleAttribute/createAttribute — no null, whitespace, /, >, or = - isValidNamespacePrefix(): For *NS methods — no null, whitespace, /, or > - isValidDoctypeName(): For createDocumentType — no null, whitespace, or > - isValidXMLName(): Preserves old XML Name production for createProcessingInstruction * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createDocumentType): * Source/WebCore/dom/Document.cpp: (WebCore::isValidHTMLElementName): (WebCore::Document::createElement): (WebCore::Document::createProcessingInstruction): (WebCore::Document::createElementNS): (WebCore::parseQualifiedName): (WebCore::Document::parseQualifiedAttributeName): (WebCore::Document::createAttribute): (WebCore::Document::createAttributeNS): * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Element.cpp: (WebCore::Element::toggleAttribute): (WebCore::Element::setAttribute): (WebCore::Element::parseAttributeName): * Source/WebCore/dom/NameValidation.cpp: Added. (WebCore::NameValidation::isValidElementName): (WebCore::NameValidation::isValidAttributeName): (WebCore::NameValidation::isValidNamespacePrefix): (WebCore::NameValidation::isValidDoctypeName): (WebCore::NameValidation::isValidXMLName): * Source/WebCore/dom/NameValidation.h: Added. * Source/WebCore/dom/Node.cpp: (WebCore::Node::checkSetPrefix): * Source/WebCore/dom/messageports/WorkerMessagePortChannelProvider.h: * Source/WebCore/editing/EditorCommand.cpp: (WebCore::executeFormatBlock): * Source/WebCore/svg/animation/SVGSMILElement.cpp: (WebCore::SVGSMILElement::constructAttributeName):
…efixes r=smaug,dom-core,devtools-reviewers,ochameau Implement "relaxed" element/attribute name-validation rules, per: - whatwg/dom#1079 - whatwg/html#7991 - whatwg/html#11453 That aligns DOM-API name behavior with HTML parser behavior - which has always allowed a wider range of characters in element and attribute names. New validation functions in nsContentUtils: - IsValidElementLocalName(): For createElement - allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - IsValidAttributeName(): For setAttribute/toggleAttribute/createAttribute - no null, whitespace, /, >, or = - IsValidNamespacePrefix(): For *NS methods - no null, whitespace, /, or > - IsValidDoctypeName(): For createDocumentType - no null, whitespace, or > - ParseQualifiedNameRelaxed(): Validates and parses qualified names with relaxed rules ParseQualifiedNameRelaxed() correctly implements the "strictly split" algorithm per the DOM spec: for qualified names with multiple colons like "f:o:o", the local name is just the second token ("o"), not everything after the first colon ("o:o"). This matches the spec's requirement to split on all colons and use only splitResult[0] as prefix and splitResult[1] as localName. Deleted outdated DOM Level 1 mochitest tests that tested old XML-based name validation rules; WPT name-validation.html provides coverage for the new relaxed rules. Removed WPT expected-failure .ini files, since all tests now pass. Differential Revision: https://phabricator.services.mozilla.com/D277822
…efixes r=smaug,dom-core,devtools-reviewers,ochameau Implement "relaxed" element/attribute name-validation rules, per: - whatwg/dom#1079 - whatwg/html#7991 - whatwg/html#11453 That aligns DOM-API name behavior with HTML parser behavior - which has always allowed a wider range of characters in element and attribute names. New validation functions in nsContentUtils: - IsValidElementLocalName(): For createElement - allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - IsValidAttributeName(): For setAttribute/toggleAttribute/createAttribute - no null, whitespace, /, >, or = - IsValidNamespacePrefix(): For *NS methods - no null, whitespace, /, or > - IsValidDoctypeName(): For createDocumentType - no null, whitespace, or > - ParseQualifiedNameRelaxed(): Validates and parses qualified names with relaxed rules ParseQualifiedNameRelaxed() correctly implements the "strictly split" algorithm per the DOM spec: for qualified names with multiple colons like "f:o:o", the local name is just the second token ("o"), not everything after the first colon ("o:o"). This matches the spec's requirement to split on all colons and use only splitResult[0] as prefix and splitResult[1] as localName. Deleted outdated DOM Level 1 mochitest tests that tested old XML-based name validation rules; WPT name-validation.html provides coverage for the new relaxed rules. Removed WPT expected-failure .ini files, since all tests now pass. Differential Revision: https://phabricator.services.mozilla.com/D277822
…efixes r=smaug,dom-core,devtools-reviewers,ochameau Implement "relaxed" element/attribute name-validation rules, per: - whatwg/dom#1079 - whatwg/html#7991 - whatwg/html#11453 That aligns DOM-API name behavior with HTML parser behavior - which has always allowed a wider range of characters in element and attribute names. New validation functions in nsContentUtils: - IsValidElementLocalName(): For createElement - allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - IsValidAttributeName(): For setAttribute/toggleAttribute/createAttribute - no null, whitespace, /, >, or = - IsValidNamespacePrefix(): For *NS methods - no null, whitespace, /, or > - IsValidDoctypeName(): For createDocumentType - no null, whitespace, or > - ParseQualifiedNameRelaxed(): Validates and parses qualified names with relaxed rules ParseQualifiedNameRelaxed() correctly implements the "strictly split" algorithm per the DOM spec: for qualified names with multiple colons like "f:o:o", the local name is just the second token ("o"), not everything after the first colon ("o:o"). This matches the spec's requirement to split on all colons and use only splitResult[0] as prefix and splitResult[1] as localName. Deleted outdated DOM Level 1 mochitest tests that tested old XML-based name validation rules; WPT name-validation.html provides coverage for the new relaxed rules. Removed WPT expected-failure .ini files, since all tests now pass. Differential Revision: https://phabricator.services.mozilla.com/D277822
https://bugs.webkit.org/show_bug.cgi?id=241419 Reviewed by NOBODY (OOPS!). Implement relaxed name-validation rules per whatwg/dom#1079, whatwg/html#7991, and whatwg/html#11453. This aligns DOM API name behavior with HTML parser behavior — which has always allowed a wider range of characters in element and attribute names. New validation functions in NameValidation.h/cpp: - isValidElementName(): For createElement — allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - isValidAttributeName(): For setAttribute/toggleAttribute/createAttribute — no null, whitespace, /, >, or = - isValidNamespacePrefix(): For *NS methods — no null, whitespace, /, or > - isValidDoctypeName(): For createDocumentType — no null, whitespace, or > - isValidXMLName(): Preserves old XML Name production for createProcessingInstruction * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createDocumentType): * Source/WebCore/dom/Document.cpp: (WebCore::createHTMLElementWithNameValidation): (WebCore::Document::createElementForBindings): (WebCore::Document::createProcessingInstruction): (WebCore::Document::createElementNS): (WebCore::Document::createAttribute): (WebCore::Document::createAttributeNS): (WebCore::isValidNameStart): Deleted. (WebCore::isValidNamePart): Deleted. (WebCore::isValidHTMLElementName): (WebCore::Document::hasValidNamespaceForElements): Deleted. (WebCore::Document::hasValidNamespaceForAttributes): Deleted. (WebCore::isValidNameNonASCII): Deleted. (WebCore::isValidNameASCII): Deleted. (WebCore::isValidNameASCIIWithoutColon): Deleted. (WebCore::Document::isValidName): Deleted. (WebCore::Document::parseQualifiedName): Deleted. * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Element.cpp: (WebCore::Element::toggleAttribute): (WebCore::Element::setAttribute): (WebCore::Element::setAttributeNS): (WebCore::Element::parseAttributeName): * Source/WebCore/dom/Element.h: * Source/WebCore/dom/NameValidation.cpp: Added. (WebCore::NameValidation::isInvalidAttributeNameCharacter): (WebCore::NameValidation::isInvalidElementNameCharacterAfterAlphaStart): (WebCore::NameValidation::isValidElementNameContinuationCharacter): (WebCore::NameValidation::isInvalidNamespacePrefixCharacter): (WebCore::NameValidation::isInvalidDoctypeNameCharacter): (WebCore::NameValidation::isValidElementName): (WebCore::NameValidation::isValidAttributeName): (WebCore::NameValidation::isValidNamespacePrefix): (WebCore::NameValidation::isValidDoctypeName): (WebCore::NameValidation::isValidASCIIXMLName): (WebCore::NameValidation::isValidXMLNameStart): (WebCore::NameValidation::isValidXMLNamePart): (WebCore::NameValidation::isValidXMLName): (WebCore::NameValidation::parseQualifiedNameToPair): (WebCore::NameValidation::parseQualifiedElementName): (WebCore::NameValidation::parseQualifiedAttributeName): (WebCore::NameValidation::hasValidNamespaceForElements): (WebCore::NameValidation::hasValidNamespaceForAttributes): * Source/WebCore/dom/NameValidation.h: Added. * Source/WebCore/dom/Node.cpp: (WebCore::Node::checkSetPrefix): * Source/WebCore/dom/ProcessingInstruction.cpp: * Source/WebCore/editing/EditorCommand.cpp: (WebCore::executeFormatBlock): * Source/WebCore/svg/animation/SVGSMILElement.cpp: (WebCore::SVGSMILElement::constructAttributeName const): * Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::handleNamespaceAttributes): (WebCore::handleElementAttributes):
https://bugs.webkit.org/show_bug.cgi?id=241419 Reviewed by NOBODY (OOPS!). Implement relaxed name-validation rules per whatwg/dom#1079, whatwg/html#7991, and whatwg/html#11453. This aligns DOM API name behavior with HTML parser behavior — which has always allowed a wider range of characters in element and attribute names. New validation functions in NameValidation.h/cpp: - isValidElementName(): For createElement — allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - isValidAttributeName(): For setAttribute/toggleAttribute/createAttribute — no null, whitespace, /, >, or = - isValidNamespacePrefix(): For *NS methods — no null, whitespace, /, or > - isValidDoctypeName(): For createDocumentType — no null, whitespace, or > - isValidXMLName(): Preserves old XML Name production for createProcessingInstruction * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createDocumentType): * Source/WebCore/dom/Document.cpp: (WebCore::createHTMLElementWithNameValidation): (WebCore::Document::createElementForBindings): (WebCore::Document::createProcessingInstruction): (WebCore::Document::createElementNS): (WebCore::Document::createAttribute): (WebCore::Document::createAttributeNS): (WebCore::isValidNameStart): Deleted. (WebCore::isValidNamePart): Deleted. (WebCore::isValidHTMLElementName): (WebCore::Document::hasValidNamespaceForElements): Deleted. (WebCore::Document::hasValidNamespaceForAttributes): Deleted. (WebCore::isValidNameNonASCII): Deleted. (WebCore::isValidNameASCII): Deleted. (WebCore::isValidNameASCIIWithoutColon): Deleted. (WebCore::Document::isValidName): Deleted. (WebCore::Document::parseQualifiedName): Deleted. * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Element.cpp: (WebCore::Element::toggleAttribute): (WebCore::Element::setAttribute): (WebCore::Element::setAttributeNS): (WebCore::Element::parseAttributeName): * Source/WebCore/dom/Element.h: * Source/WebCore/dom/NameValidation.cpp: Added. (WebCore::NameValidation::isInvalidAttributeNameCharacter): (WebCore::NameValidation::isInvalidElementNameCharacterAfterAlphaStart): (WebCore::NameValidation::isValidElementNameContinuationCharacter): (WebCore::NameValidation::isInvalidNamespacePrefixCharacter): (WebCore::NameValidation::isInvalidDoctypeNameCharacter): (WebCore::NameValidation::isValidElementName): (WebCore::NameValidation::isValidAttributeName): (WebCore::NameValidation::isValidNamespacePrefix): (WebCore::NameValidation::isValidDoctypeName): (WebCore::NameValidation::isValidASCIIXMLName): (WebCore::NameValidation::isValidXMLNameStart): (WebCore::NameValidation::isValidXMLNamePart): (WebCore::NameValidation::isValidXMLName): (WebCore::NameValidation::parseQualifiedNameToPair): (WebCore::NameValidation::parseQualifiedElementName): (WebCore::NameValidation::parseQualifiedAttributeName): (WebCore::NameValidation::hasValidNamespaceForElements): (WebCore::NameValidation::hasValidNamespaceForAttributes): * Source/WebCore/dom/NameValidation.h: Added. * Source/WebCore/dom/Node.cpp: (WebCore::Node::checkSetPrefix): * Source/WebCore/dom/ProcessingInstruction.cpp: * Source/WebCore/editing/EditorCommand.cpp: (WebCore::executeFormatBlock): * Source/WebCore/svg/animation/SVGSMILElement.cpp: (WebCore::SVGSMILElement::constructAttributeName const): * Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::handleNamespaceAttributes): (WebCore::handleElementAttributes):
https://bugs.webkit.org/show_bug.cgi?id=241419 Reviewed by NOBODY (OOPS!). Implement relaxed name-validation rules per whatwg/dom#1079, whatwg/html#7991, and whatwg/html#11453. This aligns DOM API name behavior with HTML parser behavior — which has always allowed a wider range of characters in element and attribute names. New validation functions in NameValidation.h/cpp: - isValidElementName(): For createElement — allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - isValidAttributeName(): For setAttribute/toggleAttribute/createAttribute — no null, whitespace, /, >, or = - isValidNamespacePrefix(): For *NS methods — no null, whitespace, /, or > - isValidDoctypeName(): For createDocumentType — no null, whitespace, or > - isValidXMLName(): Preserves old XML Name production for createProcessingInstruction * LayoutTests/fast/dom/dataset-expected.txt: * LayoutTests/fast/dom/dataset-xhtml-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocumentType-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createAttribute-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElement-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.js: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/name-validation-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/dataset-set-expected.txt: * LayoutTests/platform/mac/http/tests/misc/acid3-expected.txt: * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createDocumentType): * Source/WebCore/dom/Document.cpp: (WebCore::createHTMLElementWithNameValidation): (WebCore::Document::createElementForBindings): (WebCore::Document::createProcessingInstruction): (WebCore::Document::createElementNS): (WebCore::Document::createAttribute): (WebCore::Document::createAttributeNS): (WebCore::isValidNameStart): Deleted. (WebCore::isValidNamePart): Deleted. (WebCore::isValidHTMLElementName): (WebCore::Document::hasValidNamespaceForElements): Deleted. (WebCore::Document::hasValidNamespaceForAttributes): Deleted. (WebCore::isValidNameNonASCII): Deleted. (WebCore::isValidNameASCII): Deleted. (WebCore::isValidNameASCIIWithoutColon): Deleted. (WebCore::Document::isValidName): Deleted. (WebCore::Document::parseQualifiedName): Deleted. * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Element.cpp: (WebCore::Element::toggleAttribute): (WebCore::Element::setAttribute): (WebCore::Element::setAttributeNS): (WebCore::Element::parseAttributeName): * Source/WebCore/dom/Element.h: * Source/WebCore/dom/NameValidation.cpp: Added. (WebCore::NameValidation::isInvalidAttributeNameCharacter): (WebCore::NameValidation::isInvalidElementNameCharacterAfterAlphaStart): (WebCore::NameValidation::isValidElementNameContinuationCharacter): (WebCore::NameValidation::isInvalidNamespacePrefixCharacter): (WebCore::NameValidation::isInvalidDoctypeNameCharacter): (WebCore::NameValidation::isValidElementName): (WebCore::NameValidation::isValidAttributeName): (WebCore::NameValidation::isValidNamespacePrefix): (WebCore::NameValidation::isValidDoctypeName): (WebCore::NameValidation::isValidASCIIXMLName): (WebCore::NameValidation::isValidXMLNameStart): (WebCore::NameValidation::isValidXMLNamePart): (WebCore::NameValidation::isValidXMLName): (WebCore::NameValidation::parseQualifiedNameToPair): (WebCore::NameValidation::parseQualifiedElementName): (WebCore::NameValidation::parseQualifiedAttributeName): (WebCore::NameValidation::hasValidNamespaceForElements): (WebCore::NameValidation::hasValidNamespaceForAttributes): * Source/WebCore/dom/NameValidation.h: Added. * Source/WebCore/dom/Node.cpp: (WebCore::Node::checkSetPrefix): * Source/WebCore/dom/ProcessingInstruction.cpp: * Source/WebCore/editing/EditorCommand.cpp: (WebCore::executeFormatBlock): * Source/WebCore/svg/animation/SVGSMILElement.cpp: (WebCore::SVGSMILElement::constructAttributeName const): * Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::handleNamespaceAttributes): (WebCore::handleElementAttributes):
https://bugs.webkit.org/show_bug.cgi?id=241419 Reviewed by NOBODY (OOPS!). Implement relaxed name-validation rules per whatwg/dom#1079, whatwg/html#7991, and whatwg/html#11453. This aligns DOM API name behavior with HTML parser behavior — which has always allowed a wider range of characters in element and attribute names. New validation functions in NameValidation.h/cpp: - isValidElementName(): For createElement — allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - isValidAttributeName(): For setAttribute/toggleAttribute/createAttribute — no null, whitespace, /, >, or = - isValidNamespacePrefix(): For *NS methods — no null, whitespace, /, or > - isValidDoctypeName(): For createDocumentType — no null, whitespace, or > - isValidXMLName(): Preserves old XML Name production for createProcessingInstruction * LayoutTests/fast/dom/dataset-expected.txt: * LayoutTests/fast/dom/dataset-xhtml-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocumentType-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createAttribute-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElement-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.js: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/name-validation-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/dataset-set-expected.txt: * LayoutTests/platform/glib/http/tests/misc/acid3-expected.txt: * LayoutTests/platform/mac/http/tests/misc/acid3-expected.txt: * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createDocumentType): * Source/WebCore/dom/Document.cpp: (WebCore::createHTMLElementWithNameValidation): (WebCore::Document::createElementForBindings): (WebCore::Document::createProcessingInstruction): (WebCore::Document::createElementNS): (WebCore::Document::createAttribute): (WebCore::Document::createAttributeNS): (WebCore::isValidNameStart): Deleted. (WebCore::isValidNamePart): Deleted. (WebCore::isValidHTMLElementName): (WebCore::Document::hasValidNamespaceForElements): Deleted. (WebCore::Document::hasValidNamespaceForAttributes): Deleted. (WebCore::isValidNameNonASCII): Deleted. (WebCore::isValidNameASCII): Deleted. (WebCore::isValidNameASCIIWithoutColon): Deleted. (WebCore::Document::isValidName): Deleted. (WebCore::Document::parseQualifiedName): Deleted. * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Element.cpp: (WebCore::Element::toggleAttribute): (WebCore::Element::setAttribute): (WebCore::Element::setAttributeNS): (WebCore::Element::parseAttributeName): * Source/WebCore/dom/Element.h: * Source/WebCore/dom/NameValidation.cpp: Added. (WebCore::NameValidation::isInvalidAttributeNameCharacter): (WebCore::NameValidation::isInvalidElementNameCharacterAfterAlphaStart): (WebCore::NameValidation::isValidElementNameContinuationCharacter): (WebCore::NameValidation::isInvalidNamespacePrefixCharacter): (WebCore::NameValidation::isInvalidDoctypeNameCharacter): (WebCore::NameValidation::isValidElementName): (WebCore::NameValidation::isValidAttributeName): (WebCore::NameValidation::isValidNamespacePrefix): (WebCore::NameValidation::isValidDoctypeName): (WebCore::NameValidation::isValidASCIIXMLName): (WebCore::NameValidation::isValidXMLNameStart): (WebCore::NameValidation::isValidXMLNamePart): (WebCore::NameValidation::isValidXMLName): (WebCore::NameValidation::parseQualifiedNameToPair): (WebCore::NameValidation::parseQualifiedElementName): (WebCore::NameValidation::parseQualifiedAttributeName): (WebCore::NameValidation::hasValidNamespaceForElements): (WebCore::NameValidation::hasValidNamespaceForAttributes): * Source/WebCore/dom/NameValidation.h: Added. * Source/WebCore/dom/Node.cpp: (WebCore::Node::checkSetPrefix): * Source/WebCore/dom/ProcessingInstruction.cpp: * Source/WebCore/editing/EditorCommand.cpp: (WebCore::executeFormatBlock): * Source/WebCore/svg/animation/SVGSMILElement.cpp: (WebCore::SVGSMILElement::constructAttributeName const): * Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::handleNamespaceAttributes): (WebCore::handleElementAttributes):
https://bugs.webkit.org/show_bug.cgi?id=241419 Reviewed by NOBODY (OOPS!). Implement relaxed name-validation rules per whatwg/dom#1079, whatwg/html#7991, and whatwg/html#11453. This aligns DOM API name behavior with HTML parser behavior — which has always allowed a wider range of characters in element and attribute names. New validation functions in NameValidation.h/cpp: - isValidElementName(): For createElement — allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - isValidAttributeName(): For setAttribute/toggleAttribute/createAttribute — no null, whitespace, /, >, or = - isValidNamespacePrefix(): For *NS methods — no null, whitespace, /, or > - isValidDoctypeName(): For createDocumentType — no null, whitespace, or > - isValidXMLName(): Preserves old XML Name production for createProcessingInstruction * LayoutTests/fast/dom/dataset-expected.txt: * LayoutTests/fast/dom/dataset-xhtml-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocumentType-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createAttribute-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElement-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.js: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/name-validation-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/dataset-set-expected.txt: * LayoutTests/platform/glib/http/tests/misc/acid3-expected.txt: * LayoutTests/platform/mac/http/tests/misc/acid3-expected.txt: * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createDocumentType): * Source/WebCore/dom/Document.cpp: (WebCore::createHTMLElementWithNameValidation): (WebCore::Document::createElementForBindings): (WebCore::Document::createProcessingInstruction): (WebCore::Document::createElementNS): (WebCore::Document::createAttribute): (WebCore::Document::createAttributeNS): (WebCore::isValidNameStart): Deleted. (WebCore::isValidNamePart): Deleted. (WebCore::isValidHTMLElementName): (WebCore::Document::hasValidNamespaceForElements): Deleted. (WebCore::Document::hasValidNamespaceForAttributes): Deleted. (WebCore::isValidNameNonASCII): Deleted. (WebCore::isValidNameASCII): Deleted. (WebCore::isValidNameASCIIWithoutColon): Deleted. (WebCore::Document::isValidName): Deleted. (WebCore::Document::parseQualifiedName): Deleted. * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Element.cpp: (WebCore::Element::toggleAttribute): (WebCore::Element::setAttribute): (WebCore::Element::setAttributeNS): (WebCore::Element::parseAttributeName): * Source/WebCore/dom/Element.h: * Source/WebCore/dom/NameValidation.cpp: Added. (WebCore::NameValidation::isInvalidAttributeNameCharacter): (WebCore::NameValidation::isInvalidElementNameCharacterAfterAlphaStart): (WebCore::NameValidation::isValidElementNameContinuationCharacter): (WebCore::NameValidation::isInvalidNamespacePrefixCharacter): (WebCore::NameValidation::isInvalidDoctypeNameCharacter): (WebCore::NameValidation::isValidElementName): (WebCore::NameValidation::isValidAttributeName): (WebCore::NameValidation::isValidNamespacePrefix): (WebCore::NameValidation::isValidDoctypeName): (WebCore::NameValidation::isValidASCIIXMLName): (WebCore::NameValidation::isValidXMLNameStart): (WebCore::NameValidation::isValidXMLNamePart): (WebCore::NameValidation::isValidXMLName): (WebCore::NameValidation::parseQualifiedNameToPair): (WebCore::NameValidation::parseQualifiedElementName): (WebCore::NameValidation::parseQualifiedAttributeName): (WebCore::NameValidation::hasValidNamespaceForElements): (WebCore::NameValidation::hasValidNamespaceForAttributes): * Source/WebCore/dom/NameValidation.h: Added. * Source/WebCore/dom/Node.cpp: (WebCore::Node::checkSetPrefix): * Source/WebCore/dom/ProcessingInstruction.cpp: * Source/WebCore/editing/EditorCommand.cpp: (WebCore::executeFormatBlock): * Source/WebCore/svg/animation/SVGSMILElement.cpp: (WebCore::SVGSMILElement::constructAttributeName const): * Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::handleNamespaceAttributes): (WebCore::handleElementAttributes):
https://bugs.webkit.org/show_bug.cgi?id=241419 Reviewed by NOBODY (OOPS!). Implement relaxed name-validation rules per whatwg/dom#1079, whatwg/html#7991, and whatwg/html#11453. This aligns DOM API name behavior with HTML parser behavior — which has always allowed a wider range of characters in element and attribute names. New validation functions in NameValidation.h/cpp: - isValidElementName(): For createElement — allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - isValidAttributeName(): For setAttribute/toggleAttribute/createAttribute — no null, whitespace, /, >, or = - isValidNamespacePrefix(): For *NS methods — no null, whitespace, /, or > - isValidDoctypeName(): For createDocumentType — no null, whitespace, or > - isValidXMLName(): Preserves old XML Name production for createProcessingInstruction * LayoutTests/fast/dom/dataset-expected.txt: * LayoutTests/fast/dom/dataset-xhtml-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocumentType-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createAttribute-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElement-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.js: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/name-validation-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/dataset-set-expected.txt: * LayoutTests/platform/glib/http/tests/misc/acid3-expected.txt: * LayoutTests/platform/mac/http/tests/misc/acid3-expected.txt: * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createDocumentType): * Source/WebCore/dom/Document.cpp: (WebCore::createHTMLElementWithNameValidation): (WebCore::Document::createElementForBindings): (WebCore::Document::createProcessingInstruction): (WebCore::Document::createElementNS): (WebCore::Document::createAttribute): (WebCore::Document::createAttributeNS): (WebCore::isValidNameStart): Deleted. (WebCore::isValidNamePart): Deleted. (WebCore::isValidHTMLElementName): (WebCore::Document::hasValidNamespaceForElements): Deleted. (WebCore::Document::hasValidNamespaceForAttributes): Deleted. (WebCore::isValidNameNonASCII): Deleted. (WebCore::isValidNameASCII): Deleted. (WebCore::isValidNameASCIIWithoutColon): Deleted. (WebCore::Document::isValidName): Deleted. (WebCore::Document::parseQualifiedName): Deleted. * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Element.cpp: (WebCore::Element::toggleAttribute): (WebCore::Element::setAttribute): (WebCore::Element::setAttributeNS): (WebCore::Element::parseAttributeName): * Source/WebCore/dom/Element.h: * Source/WebCore/dom/NameValidation.cpp: Added. (WebCore::NameValidation::isInvalidAttributeNameCharacter): (WebCore::NameValidation::isInvalidElementNameCharacterAfterAlphaStart): (WebCore::NameValidation::isValidElementNameContinuationCharacter): (WebCore::NameValidation::isInvalidNamespacePrefixCharacter): (WebCore::NameValidation::isInvalidDoctypeNameCharacter): (WebCore::NameValidation::isValidElementName): (WebCore::NameValidation::isValidAttributeName): (WebCore::NameValidation::isValidNamespacePrefix): (WebCore::NameValidation::isValidDoctypeName): (WebCore::NameValidation::isValidASCIIXMLName): (WebCore::NameValidation::isValidXMLNameStart): (WebCore::NameValidation::isValidXMLNamePart): (WebCore::NameValidation::isValidXMLName): (WebCore::NameValidation::parseQualifiedNameToPair): (WebCore::NameValidation::parseQualifiedElementName): (WebCore::NameValidation::parseQualifiedAttributeName): (WebCore::NameValidation::hasValidNamespaceForElements): (WebCore::NameValidation::hasValidNamespaceForAttributes): * Source/WebCore/dom/NameValidation.h: Added. * Source/WebCore/dom/Node.cpp: (WebCore::Node::checkSetPrefix): * Source/WebCore/dom/ProcessingInstruction.cpp: * Source/WebCore/editing/EditorCommand.cpp: (WebCore::executeFormatBlock): * Source/WebCore/svg/animation/SVGSMILElement.cpp: (WebCore::SVGSMILElement::constructAttributeName const): * Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::handleNamespaceAttributes): (WebCore::handleElementAttributes):
https://bugs.webkit.org/show_bug.cgi?id=241419 Reviewed by Darin Adler. Implement relaxed name-validation rules per whatwg/dom#1079, whatwg/html#7991, and whatwg/html#11453. This aligns DOM API name behavior with HTML parser behavior — which has always allowed a wider range of characters in element and attribute names. New validation functions in NameValidation.h/cpp: - isValidElementName(): For createElement — allows [A-Za-z] start followed by any char except null/whitespace/>//, or [:_>=0x80] start with restricted continuation - isValidAttributeName(): For setAttribute/toggleAttribute/createAttribute — no null, whitespace, /, >, or = - isValidNamespacePrefix(): For *NS methods — no null, whitespace, /, or > - isValidDoctypeName(): For createDocumentType — no null, whitespace, or > - isValidXMLName(): Preserves old XML Name production for createProcessingInstruction * LayoutTests/fast/dom/dataset-expected.txt: * LayoutTests/fast/dom/dataset-xhtml-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocumentType-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createAttribute-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElement-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.html: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createElementNS.js: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/dom/nodes/name-validation-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/dom/elements/global-attributes/dataset-set-expected.txt: * LayoutTests/platform/glib/http/tests/misc/acid3-expected.txt: * LayoutTests/platform/mac/http/tests/misc/acid3-expected.txt: * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createDocumentType): * Source/WebCore/dom/Document.cpp: (WebCore::createHTMLElementWithNameValidation): (WebCore::Document::createElementForBindings): (WebCore::Document::createProcessingInstruction): (WebCore::Document::createElementNS): (WebCore::Document::createAttribute): (WebCore::Document::createAttributeNS): (WebCore::isValidNameStart): Deleted. (WebCore::isValidNamePart): Deleted. (WebCore::isValidHTMLElementName): (WebCore::Document::hasValidNamespaceForElements): Deleted. (WebCore::Document::hasValidNamespaceForAttributes): Deleted. (WebCore::isValidNameNonASCII): Deleted. (WebCore::isValidNameASCII): Deleted. (WebCore::isValidNameASCIIWithoutColon): Deleted. (WebCore::Document::isValidName): Deleted. (WebCore::Document::parseQualifiedName): Deleted. * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Element.cpp: (WebCore::Element::toggleAttribute): (WebCore::Element::setAttribute): (WebCore::Element::setAttributeNS): (WebCore::Element::parseAttributeName): * Source/WebCore/dom/Element.h: * Source/WebCore/dom/NameValidation.cpp: Added. (WebCore::NameValidation::isInvalidAttributeNameCharacter): (WebCore::NameValidation::isInvalidElementNameCharacterAfterAlphaStart): (WebCore::NameValidation::isValidElementNameContinuationCharacter): (WebCore::NameValidation::isInvalidNamespacePrefixCharacter): (WebCore::NameValidation::isInvalidDoctypeNameCharacter): (WebCore::NameValidation::isValidElementName): (WebCore::NameValidation::isValidAttributeName): (WebCore::NameValidation::isValidNamespacePrefix): (WebCore::NameValidation::isValidDoctypeName): (WebCore::NameValidation::isValidASCIIXMLName): (WebCore::NameValidation::isValidXMLNameStart): (WebCore::NameValidation::isValidXMLNamePart): (WebCore::NameValidation::isValidXMLName): (WebCore::NameValidation::parseQualifiedNameToPair): (WebCore::NameValidation::parseQualifiedElementName): (WebCore::NameValidation::parseQualifiedAttributeName): (WebCore::NameValidation::hasValidNamespaceForElements): (WebCore::NameValidation::hasValidNamespaceForAttributes): * Source/WebCore/dom/NameValidation.h: Added. * Source/WebCore/dom/Node.cpp: (WebCore::Node::checkSetPrefix): * Source/WebCore/dom/ProcessingInstruction.cpp: * Source/WebCore/editing/EditorCommand.cpp: (WebCore::executeFormatBlock): * Source/WebCore/svg/animation/SVGSMILElement.cpp: (WebCore::SVGSMILElement::constructAttributeName const): * Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp: (WebCore::handleNamespaceAttributes): (WebCore::handleElementAttributes): Canonical link: https://commits.webkit.org/308884@main
Stop using XML grammar productions for validating element, attribute, and doctype names. These were overly-restrictive, as it is possible to create nodes with names that don't match those productions using the HTML parser. After this change, each construct has its own custom name validation algorithm.
The only remaining dependency on XML naming rules is for processing instructions, which are uncommon and cannot be created with the HTML parser anyway.
Closes #769. Closes #849. Closes #1373.
(See WHATWG Working Mode: Changes for more details.)
Original points for discussion, discussed and concluded on in following comments. These do not reflect the currently proposed change.
=inside attribute local names. Both the parser and DOM APIs currently disallow them, except the parser allows it for the first character. I'm happy to change this if people prefer; I started with the simpler version.createProcessingInstruction()orcreateDocumentType(). We could try to simplify those too, perhaps after investigating parser behavior. But they didn't seem to be causing any real web developer pain, unlike elements and local names, so I thought it'd be better to just leave them as-is.Preview | Diff