Start fixing the handling of Element's attributes when they contain non-ASCII characters
https://bugs.webkit.org/show_bug.cgi?id=141016
Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-01-28
Reviewed by Ryosuke Niwa.
Source/WebCore:
Attribute handling does not work properly when the attribute name contains non-ASCII character.
The HTML parser tokenize those names as ASCII lowercase. Some of the code is CSS and Element use
unicode lowercase for the names. This breaks all the APIs as soon as a name contains a character
that is non-ASCII and uppercase since some APIs change it, other don't.
This patch is a first step toward fixing this mess, it only address the simple cases.
The HTML spec says the names should be compared ASCII case-insensitive, to I spread that behavior
to places that were using unicode.
Tests: fast/css/attribute-ascii-case-insensitive-html.html
fast/css/attribute-ascii-case-insensitive-xhtml-expected.xhtml
fast/css/attribute-ascii-case-insensitive-xhtml.xhtml
fast/css/attribute-ascii-case-insensitive-xml-in-html.html
fast/dom/Element/attribute-ascii-case-insensitive-1.html
fast/dom/Element/attribute-ascii-case-insensitive-2.html
fast/selectors/attribute-ascii-case-insensitive-style-update.html
fast/selectors/element-matches-attribute-ascii-case-insensitive-html.html
fast/selectors/querySelector-attribute-ascii-case-insensitive-html.html
* css/CSSSelector.cpp:
(WebCore::CSSSelector::setAttribute):
* dom/Element.cpp:
(WebCore::Element::synchronizeAttribute):
(WebCore::Element::setAttribute):
(WebCore::Element::removeAttribute):
(WebCore::Element::hasAttribute):
* dom/ElementData.cpp:
(WebCore::ElementData::findAttributeIndexByNameSlowCase):
* dom/ElementData.h:
(WebCore::ElementData::findAttributeIndexByName):
LayoutTests:
Start some basic testing.
Some tests are failing due to the more complicated case being handled incorrectly, this will
be fixed in follow ups.
* fast/css/attribute-ascii-case-insensitive-html-expected.html: Added.
* fast/css/attribute-ascii-case-insensitive-html.html: Added.
* fast/css/attribute-ascii-case-insensitive-xhtml-expected.xhtml: Added.
* fast/css/attribute-ascii-case-insensitive-xhtml.xhtml: Added.
* fast/css/attribute-ascii-case-insensitive-xml-in-html-expected.html: Added.
* fast/css/attribute-ascii-case-insensitive-xml-in-html.html: Added.
* fast/dom/Element/attribute-ascii-case-insensitive-1-expected.txt: Added.
* fast/dom/Element/attribute-ascii-case-insensitive-1.html: Added.
* fast/dom/Element/attribute-ascii-case-insensitive-2-expected.txt: Added.
* fast/dom/Element/attribute-ascii-case-insensitive-2.html: Added.
* fast/selectors/attribute-ascii-case-insensitive-style-update-expected.txt: Added.
* fast/selectors/attribute-ascii-case-insensitive-style-update.html: Added.
* fast/selectors/element-matches-attribute-ascii-case-insensitive-html-expected.txt: Added.
* fast/selectors/element-matches-attribute-ascii-case-insensitive-html.html: Added.
* fast/selectors/querySelector-attribute-ascii-case-insensitive-html-expected.txt: Added.
* fast/selectors/querySelector-attribute-ascii-case-insensitive-html.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@179323 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/fast/css/attribute-ascii-case-insensitive-html.html b/LayoutTests/fast/css/attribute-ascii-case-insensitive-html.html
new file mode 100644
index 0000000..7c982c2
--- /dev/null
+++ b/LayoutTests/fast/css/attribute-ascii-case-insensitive-html.html
@@ -0,0 +1,37 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<style>
+ target {
+ display: block;
+ height: 20px;
+ min-width: 20px;
+ float: left;
+ margin: 2px;
+ }
+ target:matches([data-Foo], [data-Æøå], [data-Foo-Æøå]) {
+ background-color: green;
+ }
+ target:matches([data-FOO], [data-ÆØÅ], [data-FOO-ÆØÅ]) {
+ color: blue;
+ }
+ target:matches([data-foo], [data-æøå], [data-foo-æøå]) {
+ border: 2px dashed red;
+ }
+</style>
+</head>
+<body>
+ <p data-Foo data-ÆØÅ data-foo-æøå>In HTML, attribute name matching is case-insensitive but only in the ASCII range.</p>
+ <p data-foo data-Foo-Æøå data-Æøå>If the test succeed, each block should be styled as described.</p>
+ <target data-Foo>Green background, blue text, dashed red border.</target>
+ <target data-FOO>Green background, blue text, dashed red border.</target>
+ <target data-foo>Green background, blue text, dashed red border.</target>
+ <target data-Æøå>Green background color.</target>
+ <target data-ÆØÅ>Blue text.</target>
+ <target data-æøå>Dashed red border.</target>
+ <target data-Foo-Æøå>Green background color.</target>
+ <target data-FOO-ÆØÅ>Blue text.</target>
+ <target data-foo-æøå>Dashed red border.</target>
+</body>
+</html>