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 <a.bah@samsung.com> 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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@148614 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 44432562
2013-04-17 Arpita Bahuguna <a.bah@samsung.com>
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 <zarvai@inf.u-szeged.hu>
[Qt] Unreviewed gardening. Updating png expected results after r148594.
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
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
<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="https://bugs.webkit.org/show_bug.cgi?id=105713"> 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
2013-04-17 Arpita Bahuguna <a.bah@samsung.com>
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 <jgriggs@blackberry.com>
[BlackBerry] Add support for filesystem: URLs to BlackBerry Media Player.
......@@ -975,11 +975,12 @@ inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment