Source/WebCore/ChangeLog

 12013-08-02 Arpita Bahuguna <a.bah@samsung.com>
 2
 3 createAttribute/setAttributeNode does not properly normalize case
 4 https://bugs.webkit.org/show_bug.cgi?id=90341
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 setAttributeNode() verifies for existing attributes in a case sensitive
 9 manner. Thus, it would add another attribute if specified in a case
 10 different from the existing one. Instead, like setAttribute(), it too
 11 should modify the existing attribute's value.
 12
 13 Test: fast/dom/Element/setAttributeNode-case-insensitivity.html
 14
 15 * dom/Element.cpp:
 16 (WebCore::Element::setAttributeNode):
 17 Passing the second param (shouldIgnoreAttributeCase) to
 18 getAttributeItemIndexForAttributeNode() method. We are now letting
 19 getAttributeItemIndexForAttributeNode() handle the case-sensitive/insensitive
 20 checking.
 21
 22 (WebCore::ElementData::getAttributeItemIndexForAttributeNode):
 23 * dom/Element.h:
 24 Added shouldIgnoreAttributeCase boolean param to the method. It passes
 25 this on to QualifiedName::matches() method.
 26
 27 * dom/QualifiedName.h:
 28 (WebCore::QualifiedName::matches):
 29 Added shouldIgnoreCase param. In turn it calls equalPossiblyIgnoringCase()
 30 with this param to perform a case-insenstive comparison.
 31
1322013-08-02 Patrick Gansterer <paroga@webkit.org>
233
334 [WIN] Fix build without precompiled header.
153645

Source/WebCore/dom/Element.cpp

@@PassRefPtr<Attr> Element::setAttributeNo
19221922 synchronizeAllAttributes();
19231923 UniqueElementData* elementData = ensureUniqueElementData();
19241924
1925  unsigned index = elementData->getAttributeItemIndexForAttributeNode(attrNode);
 1925 unsigned index = elementData->getAttributeItemIndexForAttributeNode(attrNode, shouldIgnoreAttributeCase(this));
19261926 if (index != ElementData::attributeNotFound) {
19271927 if (oldAttrNode)
19281928 detachAttrNodeFromElementWithValue(oldAttrNode.get(), elementData->attributeItem(index)->value());

@@unsigned ElementData::getAttributeItemIn
34133413 return attributeNotFound;
34143414}
34153415
3416 unsigned ElementData::getAttributeItemIndexForAttributeNode(const Attr* attr) const
 3416unsigned ElementData::getAttributeItemIndexForAttributeNode(const Attr* attr, bool shouldIgnoreAttributeCase) const
34173417{
34183418 ASSERT(attr);
34193419 const Attribute* attributes = attributeBase();
34203420 unsigned count = length();
34213421 for (unsigned i = 0; i < count; ++i) {
3422  if (attributes[i].name() == attr->qualifiedName())
 3422 if (attributes[i].name().matches(attr->qualifiedName(), shouldIgnoreAttributeCase))
34233423 return i;
34243424 }
34253425 return attributeNotFound;
153645

Source/WebCore/dom/Element.h

@@public:
8080 const Attribute* getAttributeItem(const QualifiedName&) const;
8181 unsigned getAttributeItemIndex(const QualifiedName&) const;
8282 unsigned getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
83  unsigned getAttributeItemIndexForAttributeNode(const Attr*) const;
 83 unsigned getAttributeItemIndexForAttributeNode(const Attr*, bool shouldIgnoreAttributeCase = false) const;
8484
8585 bool hasID() const { return !m_idForStyleResolution.isNull(); }
8686 bool hasClass() const { return !m_classNames.isNull(); }
153645

Source/WebCore/dom/QualifiedName.h

@@public:
7979 bool operator==(const QualifiedName& other) const { return m_impl == other.m_impl; }
8080 bool operator!=(const QualifiedName& other) const { return !(*this == other); }
8181
82  bool matches(const QualifiedName& other) const { return m_impl == other.m_impl || (localName() == other.localName() && namespaceURI() == other.namespaceURI()); }
 82 bool matches(const QualifiedName& other, bool shouldIgnoreCase = false) const { return m_impl == other.m_impl || (equalPossiblyIgnoringCase(localName(), other.localName(), shouldIgnoreCase) && namespaceURI() == other.namespaceURI()); }
8383
8484 bool hasPrefix() const { return m_impl->m_prefix != nullAtom; }
8585 void setPrefix(const AtomicString& prefix) { *this = QualifiedName(prefix, localName(), namespaceURI()); }
153645

LayoutTests/ChangeLog

 12013-08-02 Arpita Bahuguna <a.bah@samsung.com>
 2
 3 createAttribute/setAttributeNode does not properly normalize case
 4 https://bugs.webkit.org/show_bug.cgi?id=90341
 5
 6 * fast/dom/Element/setAttributeNode-case-insensitivity-expected.txt: Added.
 7 * fast/dom/Element/setAttributeNode-case-insensitivity.html: Added.
 8 Testcase for verifying that setAttributeNode() checks against existing
 9 attributes in a case insensitive manner. It updates the value of an
 10 existing attribute (in lower case) with that of the one set using
 11 setAttributeNode() (in upper case).
 12 The test also verifies the behavior of attributes when specified with
 13 namespace and prefix.
 14
1152013-08-02 Zalan Bujtas <zalan@apple.com>
216
317 Frame flattening: Change the logic on whether resize event needs to be dispatched.
153645

LayoutTests/fast/dom/Element/setAttributeNode-case-insensitivity-expected.txt

 1Test for Bugzilla bug: 90341: createAttribute/setAttributeNode does not properly normalize case.
 2This test verifies that the setAttributeNode() API checks for existing attributes case-insensitively. Thus the value of an existing attribute with the same name but in a different case should get replaced by the new value specified via the setAttributeNode() method. The issue can be manually verified if a green colored block is displayed instead of a red one.
 3
 4On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 5
 6PASS test.getAttribute('style') is test.getAttribute('STYLE')
 7PASS test.getAttributeNode('style').value is test.getAttributeNode('STYLE').value
 8Verifying that attributes with the same name but different namespaces are treated as unique entities. For the following test two different attribute values should be returned.
 9PASS test.getAttributeNodeNS('ns1', 'newattr').value is 'newattr1'
 10PASS test.getAttributeNodeNS('ns2', 'newattr').value is 'newattr2'
 11Verifying that attributes with same name but different case and having same namespaces are treated as same. In the following test the new attribute should overwrite the value of the existing one.
 12PASS test.getAttributeNodeNS('ns1', 'newattr').value is 'newattr3'
 13PASS successfullyParsed is true
 14
 15TEST COMPLETE
 16
0

LayoutTests/fast/dom/Element/setAttributeNode-case-insensitivity.html

 1<html>
 2<head>
 3<style>
 4#test {
 5 font-family: ahem;
 6 width: 50;
 7 height: 50;
 8}
 9</style>
 10<script src="../../js/resources/js-test-pre.js"></script>
 11<script>
 12function runTest()
 13{
 14 description("This test verifies that the setAttributeNode() API checks for existing attributes case-insensitively. Thus the value of an existing attribute with the same name but in a different case should get replaced by the new value specified via the setAttributeNode() method.\nThe issue can be manually verified if a green colored block is displayed instead of a red one.");
 15
 16 var test = document.getElementById("test");
 17 var newStyleAttr = document.createAttribute("STYLE");
 18 newStyleAttr.value = "background-color: green";
 19 test.setAttributeNode(newStyleAttr);
 20 if (window.testRunner) {
 21 shouldBe("test.getAttribute('style')", "test.getAttribute('STYLE')");
 22 shouldBe("test.getAttributeNode('style').value", "test.getAttributeNode('STYLE').value");
 23 }
 24
 25 debug("Verifying that attributes with the same name but different namespaces are treated as unique entities. For the following test two different attribute values should be returned.");
 26 var newAttr1 = document.createAttributeNS("ns1", "newattr");
 27 newAttr1.prefix = "prefix1";
 28 newAttr1.value = "newattr1";
 29 test.setAttributeNode(newAttr1);
 30 var newAttr2 = document.createAttributeNS("ns2", "newattr");
 31 newAttr2.prefix = "prefix2";
 32 newAttr2.value = "newattr2";
 33 test.setAttributeNode(newAttr2);
 34 if (window.testRunner) {
 35 shouldBe("test.getAttributeNodeNS('ns1', 'newattr').value", "'newattr1'");
 36 shouldBe("test.getAttributeNodeNS('ns2', 'newattr').value", "'newattr2'");
 37 }
 38
 39 debug("Verifying that attributes with same name but different case and having same namespaces are treated as same. In the following test the new attribute should overwrite the value of the existing one.");
 40 var newAttr3 = document.createAttributeNS("ns1", "NEWATTR");
 41 newAttr3.prefix = "prefix2";
 42 newAttr3.value = "newattr3";
 43 test.setAttributeNode(newAttr3);
 44
 45 if (window.testRunner) {
 46 shouldBe("test.getAttributeNodeNS('ns1', 'newattr').value", "'newattr3'");
 47
 48 isSuccessfullyParsed();
 49 test.style.display = 'none';
 50 }
 51
 52}
 53</script>
 54</head>
 55<body onload="runTest()">
 56<div>Test for Bugzilla bug:<a href="https://bugs.webkit.org/show_bug.cgi?id=90341"> 90341:</a> createAttribute/setAttributeNode does not properly normalize case.</div>
 57<div id="test" style="background-color: red">&nbsp;</div>
 58<div id="description"></div>
 59<div id="console"></div>
 60</body>
 61</html>
0