HTMLElement.classList cannot remove classnames with uppercase characters
authorarv@chromium.org <arv@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Aug 2012 02:26:35 +0000 (02:26 +0000)
committerarv@chromium.org <arv@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Aug 2012 02:26:35 +0000 (02:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93628

Reviewed by Alexey Proskuryakov.

Before this patch we were trying to be smart and determine whether we needed the update m_classNamesForQuirksMode
based on whether m_classNamesForQuirksMode.isNull(), however, m_classNamesForQuirksMode.isNull() is true when the
class name is the empty string.

We also did not update m_classNamesForQuirksMode when the class attribute was cleared.

Source/WebCore:

Updated tests.

* dom/StyledElement.cpp:
(WebCore::StyledElement::classAttributeChanged):
* html/ClassList.cpp:
(WebCore::ClassList::reset):
(WebCore::ClassList::classNames):

LayoutTests:

* fast/dom/HTMLElement/class-list-expected.txt:
* fast/dom/HTMLElement/class-list-quirks-expected.txt:
* fast/dom/HTMLElement/script-tests/class-list.js:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@125239 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLElement/class-list-expected.txt
LayoutTests/fast/dom/HTMLElement/class-list-quirks-expected.txt
LayoutTests/fast/dom/HTMLElement/script-tests/class-list.js
Source/WebCore/ChangeLog
Source/WebCore/dom/StyledElement.cpp
Source/WebCore/html/ClassList.cpp

index 932a1ee..7c7787e 100644 (file)
@@ -1,3 +1,20 @@
+2012-08-09  Erik Arvidsson  <arv@chromium.org>
+
+        HTMLElement.classList cannot remove classnames with uppercase characters
+        https://bugs.webkit.org/show_bug.cgi?id=93628
+
+        Reviewed by Alexey Proskuryakov.
+
+        Before this patch we were trying to be smart and determine whether we needed the update m_classNamesForQuirksMode
+        based on whether m_classNamesForQuirksMode.isNull(), however, m_classNamesForQuirksMode.isNull() is true when the
+        class name is the empty string.
+
+        We also did not update m_classNamesForQuirksMode when the class attribute was cleared.
+
+        * fast/dom/HTMLElement/class-list-expected.txt:
+        * fast/dom/HTMLElement/class-list-quirks-expected.txt:
+        * fast/dom/HTMLElement/script-tests/class-list.js:
+
 2012-08-09  MORITA Hajime  <morrita@google.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=93587
index bee4dd6..969b6f7 100644 (file)
@@ -72,6 +72,8 @@ PASS typeof DOMTokenList.prototype is "object"
 PASS typeof element.classList is "object"
 PASS element.classList.constructor is DOMTokenList
 PASS element.classList === element.classList is true
+PASS document.body.classList.contains("FAIL") is true
+PASS document.body.className is ""
 PASS successfullyParsed is true
 
 TEST COMPLETE
index bee4dd6..969b6f7 100644 (file)
@@ -72,6 +72,8 @@ PASS typeof DOMTokenList.prototype is "object"
 PASS typeof element.classList is "object"
 PASS element.classList.constructor is DOMTokenList
 PASS element.classList === element.classList is true
+PASS document.body.classList.contains("FAIL") is true
+PASS document.body.className is ""
 PASS successfullyParsed is true
 
 TEST COMPLETE
index a4f2f2f..ab9e163 100644 (file)
@@ -259,3 +259,9 @@ shouldBeEqualToString('typeof element.classList', 'object');
 shouldEvaluateTo('element.classList.constructor', 'DOMTokenList');
 
 shouldBeTrue('element.classList === element.classList');
+
+// Bug 93628
+document.body.classList.add('FAIL');
+shouldBeTrue('document.body.classList.contains("FAIL")');
+document.body.classList.remove('FAIL');
+shouldBeEqualToString('document.body.className', '');
index 8f65fa5..58a856d 100644 (file)
@@ -1,3 +1,24 @@
+2012-08-09  Erik Arvidsson  <arv@chromium.org>
+
+        HTMLElement.classList cannot remove classnames with uppercase characters
+        https://bugs.webkit.org/show_bug.cgi?id=93628
+
+        Reviewed by Alexey Proskuryakov.
+
+        Before this patch we were trying to be smart and determine whether we needed the update m_classNamesForQuirksMode
+        based on whether m_classNamesForQuirksMode.isNull(), however, m_classNamesForQuirksMode.isNull() is true when the
+        class name is the empty string.
+
+        We also did not update m_classNamesForQuirksMode when the class attribute was cleared.
+
+        Updated tests.
+
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::classAttributeChanged):
+        * html/ClassList.cpp:
+        (WebCore::ClassList::reset):
+        (WebCore::ClassList::classNames):
+
 2012-08-09  Yuta Kitamura  <yutak@chromium.org>
 
         Unreviewed, Chromium-mac (clang) build fix for r125230.
index 266255a..c5616b0 100644 (file)
@@ -170,10 +170,12 @@ void StyledElement::classAttributeChanged(const AtomicString& newClassString)
     if (hasClass) {
         const bool shouldFoldCase = document()->inQuirksMode();
         ensureAttributeData()->setClass(newClassString, shouldFoldCase);
-        if (DOMTokenList* classList = optionalClassList())
-            static_cast<ClassList*>(classList)->reset(newClassString);
     } else if (attributeData())
         mutableAttributeData()->clearClass();
+
+    if (DOMTokenList* classList = optionalClassList())
+        static_cast<ClassList*>(classList)->reset(newClassString);
+
     setNeedsStyleRecalc();
 }
 
index 2ea8382..a325a12 100644 (file)
@@ -131,14 +131,14 @@ String ClassList::toString() const
 
 void ClassList::reset(const String& newClassName)
 {
-    if (!m_classNamesForQuirksMode.isNull())
+    if (m_element->document()->inQuirksMode())
         m_classNamesForQuirksMode.set(newClassName, false);
 }
 
 const SpaceSplitString& ClassList::classNames() const
 {
     ASSERT(m_element->hasClass());
-    if (!m_classNamesForQuirksMode.isNull())
+    if (m_element->document()->inQuirksMode())
         return m_classNamesForQuirksMode;
     return m_element->attributeData()->classNames();
 }