font shorthand with inherit keyword incorrectly parsed and rendered
authoralexis.menard@openbossa.org <alexis.menard@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Feb 2012 21:00:24 +0000 (21:00 +0000)
committeralexis.menard@openbossa.org <alexis.menard@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Feb 2012 21:00:24 +0000 (21:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=20181

Reviewed by Tony Chang.

Source/WebCore:

As stated in http://www.w3.org/TR/CSS21/changes.html#q142
if the inherit (and also by extension initial) is encountered in the
middle of the shorthand then the property becomes invalid.

Test: fast/css/font-shorthand-mix-inherit.html

* css/CSSParser.cpp:
(WebCore::CSSParser::parseFont):
(WebCore::CSSParser::parseFontFamily):

LayoutTests:

* fast/css/font-shorthand-mix-inherit-expected.txt: Added.
* fast/css/font-shorthand-mix-inherit.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/css/font-shorthand-mix-inherit-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/font-shorthand-mix-inherit.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSParser.cpp

index b670588..1e17b24 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-14  Alexis Menard  <alexis.menard@openbossa.org>
+
+        font shorthand with inherit keyword incorrectly parsed and rendered
+        https://bugs.webkit.org/show_bug.cgi?id=20181
+
+        Reviewed by Tony Chang.
+
+        * fast/css/font-shorthand-mix-inherit-expected.txt: Added.
+        * fast/css/font-shorthand-mix-inherit.html: Added.
+
 2012-02-14  Abhishek Arya  <inferno@chromium.org>
 
         Crash due to incorrect firing of mutation event during class attribute parsing.
diff --git a/LayoutTests/fast/css/font-shorthand-mix-inherit-expected.txt b/LayoutTests/fast/css/font-shorthand-mix-inherit-expected.txt
new file mode 100644 (file)
index 0000000..65a6697
--- /dev/null
@@ -0,0 +1,20 @@
+Test for WebKit bug 20181 : font shorthand with inherit keyword incorrectly parsed and rendered
+
+PASS test.style.getPropertyValue('font') is '12pt/14pt sans-serif'
+PASS test.style.getPropertyValue('font') is 'inherit'
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS test.style.getPropertyValue('font') is ''
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/css/font-shorthand-mix-inherit.html b/LayoutTests/fast/css/font-shorthand-mix-inherit.html
new file mode 100644 (file)
index 0000000..fa95c38
--- /dev/null
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Test for WebKit bug 20181 : font shorthand with inherit keyword incorrectly parsed and rendered</title>
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description">Test for WebKit bug <a href="https://bugs.webkit.org/show_bug.cgi?id=20181">20181</a> : font shorthand with inherit keyword incorrectly parsed and rendered</p>
+<div id="console"></div>
+
+<div id="tests_container">
+
+<div id="test"></div>
+
+</div>
+
+<script>
+    var test = document.getElementById("test");
+
+    // Sanity check.
+    test.style.font = "12pt/14pt sans-serif";
+    shouldBe("test.style.getPropertyValue('font')", "'12pt/14pt sans-serif'");
+    test.style.font = "";
+    test.style.font = "inherit";
+    shouldBe("test.style.getPropertyValue('font')", "'inherit'");
+    test.style.font = "";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "12pt/14pt inherit";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "12pt/14pt bold inherit";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "italic 12pt/14pt bold inherit";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "italic 12pt/14pt bold arial inherit";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "x-large/110% 'new century schoolbook', serif, inherit";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = " 'inherit'";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "italic inherit 12pt/14pt bold arial inherit";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "arial inherit";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "Arial, Helvetica, inherit, sans-serif;";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "inherit, sans-serif;";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    test.style.font = "italic inherit 12pt/14pt bold arial initial";
+    shouldBe("test.style.getPropertyValue('font')", "''");
+    // clean up after ourselves
+    var tests_container = document.getElementById("tests_container");
+    tests_container.parentNode.removeChild(tests_container);
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 4017ffb..1bcafee 100644 (file)
@@ -1,3 +1,20 @@
+2012-02-14  Alexis Menard  <alexis.menard@openbossa.org>
+
+        font shorthand with inherit keyword incorrectly parsed and rendered
+        https://bugs.webkit.org/show_bug.cgi?id=20181
+
+        Reviewed by Tony Chang.
+
+        As stated in http://www.w3.org/TR/CSS21/changes.html#q142
+        if the inherit (and also by extension initial) is encountered in the
+        middle of the shorthand then the property becomes invalid.
+
+        Test: fast/css/font-shorthand-mix-inherit.html
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseFont):
+        (WebCore::CSSParser::parseFontFamily):
+
 2012-02-14  Abhishek Arya  <inferno@chromium.org>
 
         Crash due to incorrect firing of mutation event during class attribute parsing.
index a1258ff..ab76051 100644 (file)
@@ -4147,6 +4147,8 @@ bool CSSParser::parseFont(bool important)
     // Optional font-style, font-variant and font-weight.
     while (value) {
         int id = value->id;
+        if (id == CSSValueInitial || id == CSSValueInherit)
+            return false;
         if (id) {
             if (id == CSSValueNormal) {
                 // It's the initial value for all three, so mark the corresponding longhand as explicit.
@@ -4216,6 +4218,9 @@ bool CSSParser::parseFont(bool important)
     if (!value)
         return false;
 
+    if (value->id == CSSValueInitial || value->id == CSSValueInherit)
+        return false;
+
     // Set undefined values to default.
     if (!font->style)
         font->style = cssValuePool()->createIdentifierValue(CSSValueNormal);
@@ -4234,6 +4239,9 @@ bool CSSParser::parseFont(bool important)
     if (!font->size || !value)
         return false;
 
+    if (value->id == CSSValueInitial || value->id == CSSValueInherit)
+        return false;
+
     if (value->unit == CSSParserValue::Operator && value->iValue == '/') {
         // The line-height property.
         value = m_valueList->next();
@@ -4252,6 +4260,9 @@ bool CSSParser::parseFont(bool important)
             return false;
     }
 
+    if (value->id == CSSValueInitial || value->id == CSSValueInherit)
+        return false;
+
     if (!font->lineHeight)
         font->lineHeight = cssValuePool()->createIdentifierValue(CSSValueNormal);
 
@@ -4283,6 +4294,8 @@ PassRefPtr<CSSValueList> CSSParser::parseFontFamily()
 
     FontFamilyValue* currFamily = 0;
     while (value) {
+        if (value->id == CSSValueInitial || value->id == CSSValueInherit)
+            return 0;
         CSSParserValue* nextValue = m_valueList->next();
         bool nextValBreaksFont = !nextValue ||
                                  (nextValue->unit == CSSParserValue::Operator && nextValue->iValue == ',');