Skip to content

Commit ab1580d

Browse files
Allow more characters in element/attribute names and prefixes
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):
1 parent e96d3a3 commit ab1580d

30 files changed

+601
-453
lines changed

LayoutTests/fast/dom/dataset-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ PASS testSet('à', 'data-à') is true
3333
PASS testSet('foo豈', 'data-foo豈') is true
3434

3535
PASS testSet('-foo', 'dummy') threw exception SyntaxError: The string did not match the expected pattern..
36-
PASS testSet('foo ', 'dummy') threw exception InvalidCharacterError: Invalid qualified name: 'data-foo '.
36+
PASS testSet('foo ', 'dummy') threw exception InvalidCharacterError: Invalid attribute name: 'data-foo '.
3737

3838
PASS testDelete('data-foo', 'foo') is true
3939
PASS testDelete('data-foo-bar', 'fooBar') is true

LayoutTests/fast/dom/dataset-xhtml-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PASS testSet('à', 'data-à') is true
2424
PASS testSet('foo豈', 'data-foo豈') is true
2525

2626
PASS testSet('-foo', 'dummy') threw exception SyntaxError: The string did not match the expected pattern..
27-
PASS testSet('foo ', 'dummy') threw exception InvalidCharacterError: Invalid qualified name: 'data-foo '.
27+
PASS testSet('foo ', 'dummy') threw exception InvalidCharacterError: Invalid attribute name: 'data-foo '.
2828

2929
PASS testDelete('data-foo', 'foo') is true
3030
PASS testDelete('data-foo-bar', 'fooBar') is true

LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument-expected.txt

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,39 @@ PASS createDocument test: characterSet aliases for null,"foo1",null
1919
PASS createDocument test: null,"ெfoo",null,null
2020
PASS createDocument test: metadata for null,"ெfoo",null
2121
PASS createDocument test: characterSet aliases for null,"ெfoo",null
22-
FAIL createDocument test: null,";foo",null,null Invalid qualified name start in ';foo'
23-
FAIL createDocument test: metadata for null,";foo",null Invalid qualified name start in ';foo'
24-
FAIL createDocument test: characterSet aliases for null,";foo",null Invalid qualified name start in ';foo'
22+
PASS createDocument test: null,";foo",null,null
23+
PASS createDocument test: metadata for null,";foo",null
24+
PASS createDocument test: characterSet aliases for null,";foo",null
2525
PASS createDocument test: null,"}foo",null,"INVALID_CHARACTER_ERR"
26-
FAIL createDocument test: null,"f}oo",null,null Invalid qualified name part in 'f}oo'
27-
FAIL createDocument test: metadata for null,"f}oo",null Invalid qualified name part in 'f}oo'
28-
FAIL createDocument test: characterSet aliases for null,"f}oo",null Invalid qualified name part in 'f}oo'
29-
FAIL createDocument test: null,"foo}",null,null Invalid qualified name part in 'foo}'
30-
FAIL createDocument test: metadata for null,"foo}",null Invalid qualified name part in 'foo}'
31-
FAIL createDocument test: characterSet aliases for null,"foo}",null Invalid qualified name part in 'foo}'
32-
FAIL createDocument test: null,"\ufffffoo",null,null Invalid qualified name start in '￿foo'
33-
FAIL createDocument test: metadata for null,"\ufffffoo",null Invalid qualified name start in '￿foo'
34-
FAIL createDocument test: characterSet aliases for null,"\ufffffoo",null Invalid qualified name start in '￿foo'
35-
FAIL createDocument test: null,"f\uffffoo",null,null Invalid qualified name part in 'f￿oo'
36-
FAIL createDocument test: metadata for null,"f\uffffoo",null Invalid qualified name part in 'f￿oo'
37-
FAIL createDocument test: characterSet aliases for null,"f\uffffoo",null Invalid qualified name part in 'f￿oo'
38-
FAIL createDocument test: null,"foo\uffff",null,null Invalid qualified name part in 'foo￿'
39-
FAIL createDocument test: metadata for null,"foo\uffff",null Invalid qualified name part in 'foo￿'
40-
FAIL createDocument test: characterSet aliases for null,"foo\uffff",null Invalid qualified name part in 'foo￿'
26+
PASS createDocument test: null,"f}oo",null,null
27+
PASS createDocument test: metadata for null,"f}oo",null
28+
PASS createDocument test: characterSet aliases for null,"f}oo",null
29+
PASS createDocument test: null,"foo}",null,null
30+
PASS createDocument test: metadata for null,"foo}",null
31+
PASS createDocument test: characterSet aliases for null,"foo}",null
32+
PASS createDocument test: null,"\ufffffoo",null,null
33+
PASS createDocument test: metadata for null,"\ufffffoo",null
34+
PASS createDocument test: characterSet aliases for null,"\ufffffoo",null
35+
PASS createDocument test: null,"f\uffffoo",null,null
36+
PASS createDocument test: metadata for null,"f\uffffoo",null
37+
PASS createDocument test: characterSet aliases for null,"f\uffffoo",null
38+
PASS createDocument test: null,"foo\uffff",null,null
39+
PASS createDocument test: metadata for null,"foo\uffff",null
40+
PASS createDocument test: characterSet aliases for null,"foo\uffff",null
4141
PASS createDocument test: null,"<foo",null,"INVALID_CHARACTER_ERR"
4242
PASS createDocument test: null,"foo>",null,"INVALID_CHARACTER_ERR"
4343
PASS createDocument test: null,"<foo>",null,"INVALID_CHARACTER_ERR"
44-
FAIL createDocument test: null,"f<oo",null,null Invalid qualified name part in 'f<oo'
45-
FAIL createDocument test: metadata for null,"f<oo",null Invalid qualified name part in 'f<oo'
46-
FAIL createDocument test: characterSet aliases for null,"f<oo",null Invalid qualified name part in 'f<oo'
44+
PASS createDocument test: null,"f<oo",null,null
45+
PASS createDocument test: metadata for null,"f<oo",null
46+
PASS createDocument test: characterSet aliases for null,"f<oo",null
4747
PASS createDocument test: null,"^^",null,"INVALID_CHARACTER_ERR"
4848
PASS createDocument test: null,"fo o",null,"INVALID_CHARACTER_ERR"
4949
PASS createDocument test: null,"-foo",null,"INVALID_CHARACTER_ERR"
5050
PASS createDocument test: null,".foo",null,"INVALID_CHARACTER_ERR"
5151
PASS createDocument test: null,":foo",null,"INVALID_CHARACTER_ERR"
5252
PASS createDocument test: null,"f:oo",null,"NAMESPACE_ERR"
5353
PASS createDocument test: null,"foo:",null,"INVALID_CHARACTER_ERR"
54-
FAIL createDocument test: null,"f:o:o",null,"NAMESPACE_ERR" assert_throws_dom: function "function() { document.implementation.createDocument(namespace, qualifiedName, doctype) }" threw object "InvalidCharacterError: Unexpected colon in qualified name 'f:o:o'" that is not a DOMException NAMESPACE_ERR: property "code" is equal to 5, expected 14
54+
PASS createDocument test: null,"f:o:o",null,"NAMESPACE_ERR"
5555
PASS createDocument test: null,":",null,"INVALID_CHARACTER_ERR"
5656
PASS createDocument test: null,"xml",null,null
5757
PASS createDocument test: metadata for null,"xml",null
@@ -89,7 +89,7 @@ PASS createDocument test: characterSet aliases for undefined,"foo1",null
8989
PASS createDocument test: undefined,":foo",null,"INVALID_CHARACTER_ERR"
9090
PASS createDocument test: undefined,"f:oo",null,"NAMESPACE_ERR"
9191
PASS createDocument test: undefined,"foo:",null,"INVALID_CHARACTER_ERR"
92-
PASS createDocument test: undefined,"f::oo",null,"INVALID_CHARACTER_ERR"
92+
PASS createDocument test: undefined,"f::oo",null,"NAMESPACE_ERR"
9393
PASS createDocument test: undefined,"xml",null,null
9494
PASS createDocument test: metadata for undefined,"xml",null
9595
PASS createDocument test: characterSet aliases for undefined,"xml",null
@@ -105,9 +105,9 @@ PASS createDocument test: metadata for "http://example.com/","foo",null
105105
PASS createDocument test: characterSet aliases for "http://example.com/","foo",null
106106
PASS createDocument test: "http://example.com/","1foo",null,"INVALID_CHARACTER_ERR"
107107
PASS createDocument test: "http://example.com/","<foo>",null,"INVALID_CHARACTER_ERR"
108-
FAIL createDocument test: "http://example.com/","fo<o",null,null Invalid qualified name part in 'fo<o'
109-
FAIL createDocument test: metadata for "http://example.com/","fo<o",null Invalid qualified name part in 'fo<o'
110-
FAIL createDocument test: characterSet aliases for "http://example.com/","fo<o",null Invalid qualified name part in 'fo<o'
108+
PASS createDocument test: "http://example.com/","fo<o",null,null
109+
PASS createDocument test: metadata for "http://example.com/","fo<o",null
110+
PASS createDocument test: characterSet aliases for "http://example.com/","fo<o",null
111111
PASS createDocument test: "http://example.com/","-foo",null,"INVALID_CHARACTER_ERR"
112112
PASS createDocument test: "http://example.com/",".foo",null,"INVALID_CHARACTER_ERR"
113113
PASS createDocument test: "http://example.com/","f1oo",null,null
@@ -120,36 +120,38 @@ PASS createDocument test: "http://example.com/",":foo",null,"INVALID_CHARACTER_E
120120
PASS createDocument test: "http://example.com/","f:oo",null,null
121121
PASS createDocument test: metadata for "http://example.com/","f:oo",null
122122
PASS createDocument test: characterSet aliases for "http://example.com/","f:oo",null
123-
FAIL createDocument test: "http://example.com/","f:o:o",null,null Unexpected colon in qualified name 'f:o:o'
124-
FAIL createDocument test: metadata for "http://example.com/","f:o:o",null Unexpected colon in qualified name 'f:o:o'
125-
FAIL createDocument test: characterSet aliases for "http://example.com/","f:o:o",null Unexpected colon in qualified name 'f:o:o'
123+
PASS createDocument test: "http://example.com/","f:o:o",null,null
124+
PASS createDocument test: metadata for "http://example.com/","f:o:o",null
125+
PASS createDocument test: characterSet aliases for "http://example.com/","f:o:o",null
126126
PASS createDocument test: "http://example.com/","foo:",null,"INVALID_CHARACTER_ERR"
127-
PASS createDocument test: "http://example.com/","f::oo",null,"INVALID_CHARACTER_ERR"
127+
PASS createDocument test: "http://example.com/","f::oo",null,null
128+
PASS createDocument test: metadata for "http://example.com/","f::oo",null
129+
PASS createDocument test: characterSet aliases for "http://example.com/","f::oo",null
128130
PASS createDocument test: "http://example.com/","a:0",null,"INVALID_CHARACTER_ERR"
129-
FAIL createDocument test: "http://example.com/","0:a",null,null Invalid qualified name start in '0:a'
130-
FAIL createDocument test: metadata for "http://example.com/","0:a",null Invalid qualified name start in '0:a'
131-
FAIL createDocument test: characterSet aliases for "http://example.com/","0:a",null Invalid qualified name start in '0:a'
131+
PASS createDocument test: "http://example.com/","0:a",null,null
132+
PASS createDocument test: metadata for "http://example.com/","0:a",null
133+
PASS createDocument test: characterSet aliases for "http://example.com/","0:a",null
132134
PASS createDocument test: "http://example.com/","a:_",null,null
133135
PASS createDocument test: metadata for "http://example.com/","a:_",null
134136
PASS createDocument test: characterSet aliases for "http://example.com/","a:_",null
135137
PASS createDocument test: "http://example.com/","a:ெ",null,null
136138
PASS createDocument test: metadata for "http://example.com/","a:ெ",null
137139
PASS createDocument test: characterSet aliases for "http://example.com/","a:ெ",null
138-
FAIL createDocument test: "http://example.com/","a:;",null,null Invalid qualified name start in 'a:;'
139-
FAIL createDocument test: metadata for "http://example.com/","a:;",null Invalid qualified name start in 'a:;'
140-
FAIL createDocument test: characterSet aliases for "http://example.com/","a:;",null Invalid qualified name start in 'a:;'
141-
FAIL createDocument test: "http://example.com/","a:̀",null,null Invalid qualified name start in 'a:̀'
142-
FAIL createDocument test: metadata for "http://example.com/","a:̀",null Invalid qualified name start in 'a:̀'
143-
FAIL createDocument test: characterSet aliases for "http://example.com/","a:̀",null Invalid qualified name start in 'a:̀'
140+
PASS createDocument test: "http://example.com/","a:;",null,null
141+
PASS createDocument test: metadata for "http://example.com/","a:;",null
142+
PASS createDocument test: characterSet aliases for "http://example.com/","a:;",null
143+
PASS createDocument test: "http://example.com/","a:̀",null,null
144+
PASS createDocument test: metadata for "http://example.com/","a:̀",null
145+
PASS createDocument test: characterSet aliases for "http://example.com/","a:̀",null
144146
PASS createDocument test: "http://example.com/","ெ:a",null,null
145147
PASS createDocument test: metadata for "http://example.com/","ெ:a",null
146148
PASS createDocument test: characterSet aliases for "http://example.com/","ெ:a",null
147-
FAIL createDocument test: "http://example.com/","̀:a",null,null Invalid qualified name start in '̀:a'
148-
FAIL createDocument test: metadata for "http://example.com/","̀:a",null Invalid qualified name start in '̀:a'
149-
FAIL createDocument test: characterSet aliases for "http://example.com/","̀:a",null Invalid qualified name start in '̀:a'
150-
FAIL createDocument test: "http://example.com/",";:a",null,null Invalid qualified name start in ';:a'
151-
FAIL createDocument test: metadata for "http://example.com/",";:a",null Invalid qualified name start in ';:a'
152-
FAIL createDocument test: characterSet aliases for "http://example.com/",";:a",null Invalid qualified name start in ';:a'
149+
PASS createDocument test: "http://example.com/","̀:a",null,null
150+
PASS createDocument test: metadata for "http://example.com/","̀:a",null
151+
PASS createDocument test: characterSet aliases for "http://example.com/","̀:a",null
152+
PASS createDocument test: "http://example.com/",";:a",null,null
153+
PASS createDocument test: metadata for "http://example.com/",";:a",null
154+
PASS createDocument test: characterSet aliases for "http://example.com/",";:a",null
153155
PASS createDocument test: "http://example.com/","a:aெ",null,null
154156
PASS createDocument test: metadata for "http://example.com/","a:aெ",null
155157
PASS createDocument test: characterSet aliases for "http://example.com/","a:aெ",null
@@ -209,7 +211,9 @@ PASS createDocument test: characterSet aliases for "http://example.com/","XMLNS:
209211
PASS createDocument test: "http://example.com/","xmlfoo:bar",null,null
210212
PASS createDocument test: metadata for "http://example.com/","xmlfoo:bar",null
211213
PASS createDocument test: characterSet aliases for "http://example.com/","xmlfoo:bar",null
212-
PASS createDocument test: "http://example.com/","prefix::local",null,"INVALID_CHARACTER_ERR"
214+
PASS createDocument test: "http://example.com/","prefix::local",null,null
215+
PASS createDocument test: metadata for "http://example.com/","prefix::local",null
216+
PASS createDocument test: characterSet aliases for "http://example.com/","prefix::local",null
213217
PASS createDocument test: "http://example.com/","namespaceURI:{",null,"INVALID_CHARACTER_ERR"
214218
PASS createDocument test: "http://example.com/","namespaceURI:}",null,"INVALID_CHARACTER_ERR"
215219
PASS createDocument test: "http://example.com/","namespaceURI:~",null,"INVALID_CHARACTER_ERR"

LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
var names = []
117117
var firstColonIndex = qualified.indexOf(":")
118118
if (firstColonIndex >= 0) {
119-
names = qualifiedName.split(":", 2);
119+
names = [qualified.substring(0, firstColonIndex), qualified.substring(firstColonIndex + 1)];
120120
} else {
121121
names = [null, qualified]
122122
}

0 commit comments

Comments
 (0)