Title: [148614] trunk
Revision
148614
Author
[email protected]
Date
2013-04-17 09:14:37 -0700 (Wed, 17 Apr 2013)

Log Message

getAttribute does not behave correctly for mixed-case attributes on HTML elements
https://bugs.webkit.org/show_bug.cgi?id=105713

Patch by Arpita Bahuguna <[email protected]> on 2013-04-17
Reviewed by Andreas Kling.

Source/WebCore:

getAttribute() and getAttributeNode() APIs do not convert the
passed attribute name to lowercase before comparing against the
existing attributes.
The specification however states that the passed name should
be converted to ASCII lowercase before checking for the existence
of the given attribute. [www.w3.org/TR/domcore/#dom-element-getattribute]

Test: fast/dom/Element/getAttribute-case-insensitivity.html

* dom/Element.h:
(WebCore::ElementData::getAttributeItemIndex):
getAttributeItemIndex() accepts a bool param 'shouldIgnoreAttributeCase'
which specifies whether or not the attribute's case should be ignored
before comparison but we don't really convert the passed name to lowercase
before carrying out the comparison.

Thus, when called from APIs such as getAttribute() and getAttributeNode()
which do not explicitally convert the attribute name to lowercase
before calling on this method, it fails to carry out a case-insensitive
search.

Have thus made changes to convert the passed attribute's name to
lowercase if 'shouldIgnoreAttributeCase' is true.

LayoutTests:

* fast/dom/Element/getAttribute-case-insensitivity-expected.txt: Added.
* fast/dom/Element/getAttribute-case-insensitivity.html: Added.
Layout test added for verifying that getAttribute() and getAttributeNode()
APIs convert the passed attribute name to lowercase before comparing
against the existing attributes.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (148613 => 148614)


--- trunk/LayoutTests/ChangeLog	2013-04-17 15:56:46 UTC (rev 148613)
+++ trunk/LayoutTests/ChangeLog	2013-04-17 16:14:37 UTC (rev 148614)
@@ -1,3 +1,16 @@
+2013-04-17  Arpita Bahuguna  <[email protected]>
+
+        getAttribute does not behave correctly for mixed-case attributes on HTML elements
+        https://bugs.webkit.org/show_bug.cgi?id=105713
+
+        Reviewed by Andreas Kling.
+
+        * fast/dom/Element/getAttribute-case-insensitivity-expected.txt: Added.
+        * fast/dom/Element/getAttribute-case-insensitivity.html: Added.
+        Layout test added for verifying that getAttribute() and getAttributeNode()
+        APIs convert the passed attribute name to lowercase before comparing
+        against the existing attributes.
+
 2013-04-17  Zoltan Arvai  <[email protected]>
 
         [Qt] Unreviewed gardening. Updating png expected results after r148594.

Added: trunk/LayoutTests/fast/dom/Element/getAttribute-case-insensitivity-expected.txt (0 => 148614)


--- trunk/LayoutTests/fast/dom/Element/getAttribute-case-insensitivity-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/getAttribute-case-insensitivity-expected.txt	2013-04-17 16:14:37 UTC (rev 148614)
@@ -0,0 +1,15 @@
+Test for Bugzilla bug: 105713: getAttribute does not behave correctly for mixed-case attributes on HTML testements.
+This test verifies that the getAttribute() and the getAttributeNode() APIs convert the passed attribute name to lowercase before comparing against existing attributes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS test.getAttribute('NEWATTR') is 'PASS'
+PASS test.getAttributeNode('NEWATTR').value is 'PASS'
+PASS test.getAttributeNS(null, 'NEWATTR') is 'FAIL'
+PASS test.getAttribute('newattr') is 'PASS'
+PASS test.getAttributeNode('newattr').value is 'PASS'
+PASS test.getAttributeNS(null, 'newattr') is 'PASS'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Element/getAttribute-case-insensitivity.html (0 => 148614)


--- trunk/LayoutTests/fast/dom/Element/getAttribute-case-insensitivity.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/getAttribute-case-insensitivity.html	2013-04-17 16:14:37 UTC (rev 148614)
@@ -0,0 +1,32 @@
+<html>
+<head>
+<script src=""
+<script>
+function runTest()
+{
+    description("This test verifies that the getAttribute() and the getAttributeNode() APIs convert the passed attribute name to lowercase before comparing against existing attributes.");
+    
+    var test = document.getElementById("test");
+    test.setAttributeNS(null, "NEWATTR", "FAIL");
+    test.setAttributeNS(null, "newattr", "PASS");
+    
+    if (window.testRunner) {
+        shouldBe("test.getAttribute('NEWATTR')", "'PASS'");
+        shouldBe("test.getAttributeNode('NEWATTR').value", "'PASS'");
+        shouldBe("test.getAttributeNS(null, 'NEWATTR')", "'FAIL'");
+        shouldBe("test.getAttribute('newattr')", "'PASS'");
+        shouldBe("test.getAttributeNode('newattr').value", "'PASS'");
+        shouldBe("test.getAttributeNS(null, 'newattr')", "'PASS'");
+    
+        isSuccessfullyParsed();
+    }
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<div>Test for Bugzilla bug:<a href="" 105713:</a>  getAttribute does not behave correctly for mixed-case attributes on HTML testements.</div>
+<div id="test"></div>
+<div id="description"></div>
+<div id="console"></div>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (148613 => 148614)


--- trunk/Source/WebCore/ChangeLog	2013-04-17 15:56:46 UTC (rev 148613)
+++ trunk/Source/WebCore/ChangeLog	2013-04-17 16:14:37 UTC (rev 148614)
@@ -1,3 +1,34 @@
+2013-04-17  Arpita Bahuguna  <[email protected]>
+
+        getAttribute does not behave correctly for mixed-case attributes on HTML elements
+        https://bugs.webkit.org/show_bug.cgi?id=105713
+
+        Reviewed by Andreas Kling.
+
+        getAttribute() and getAttributeNode() APIs do not convert the
+        passed attribute name to lowercase before comparing against the
+        existing attributes.
+        The specification however states that the passed name should
+        be converted to ASCII lowercase before checking for the existence
+        of the given attribute. [www.w3.org/TR/domcore/#dom-element-getattribute]
+
+        Test: fast/dom/Element/getAttribute-case-insensitivity.html
+
+        * dom/Element.h:
+        (WebCore::ElementData::getAttributeItemIndex):
+        getAttributeItemIndex() accepts a bool param 'shouldIgnoreAttributeCase'
+        which specifies whether or not the attribute's case should be ignored
+        before comparison but we don't really convert the passed name to lowercase
+        before carrying out the comparison.
+
+        Thus, when called from APIs such as getAttribute() and getAttributeNode()
+        which do not explicitally convert the attribute name to lowercase
+        before calling on this method, it fails to carry out a case-insensitive
+        search.
+
+        Have thus made changes to convert the passed attribute's name to
+        lowercase if 'shouldIgnoreAttributeCase' is true.
+
 2013-04-17  John Griggs  <[email protected]>
 
         [BlackBerry] Add support for filesystem: URLs to BlackBerry Media Player.

Modified: trunk/Source/WebCore/dom/Element.h (148613 => 148614)


--- trunk/Source/WebCore/dom/Element.h	2013-04-17 15:56:46 UTC (rev 148613)
+++ trunk/Source/WebCore/dom/Element.h	2013-04-17 16:14:37 UTC (rev 148614)
@@ -975,11 +975,12 @@
     unsigned len = length();
     bool doSlowCheck = shouldIgnoreAttributeCase;
 
+    const AtomicString caseAdjustedName = shouldIgnoreAttributeCase ? name.lower() : name;
     // Optimize for the case where the attribute exists and its name exactly matches.
     for (unsigned i = 0; i < len; ++i) {
         const Attribute* attribute = attributeItem(i);
         if (!attribute->name().hasPrefix()) {
-            if (name == attribute->localName())
+            if (caseAdjustedName == attribute->localName())
                 return i;
         } else
             doSlowCheck = true;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to