Title: [115972] trunk
Revision
115972
Author
[email protected]
Date
2012-05-03 08:11:27 -0700 (Thu, 03 May 2012)

Log Message

Remove extra checks for empty string when parsing CSS value
https://bugs.webkit.org/show_bug.cgi?id=85480

Reviewed by Alexis Menard.

Source/WebCore:

Each parse value helper function was checking whether the value string was empty. For the
common case this check is already done by StylePropertySet::setProperty(). So this patch
make CSSParser::parseValue() assume the value string is not empty, and fix the other two
clients.

Test: fast/html/font-face-empty-should-not-crash.html

* css/CSSParser.cpp:
(WebCore::parseColorValue): Replace the string empty check by an ASSERT() to document
function's expectations.
(WebCore::parseSimpleLengthValue): Ditto.
(WebCore::parseKeywordValue): Ditto.
(WebCore::CSSParser::parseFontFaceValue): This will be covered by the added test.
(WebCore::CSSParser::parseValue):
* css/WebKitCSSMatrix.cpp:
(WebCore::WebKitCSSMatrix::setMatrixValue): This is already covered by
transforms/cssmatrix-2d-interface.xhtml.

LayoutTests:

* fast/html/font-face-empty-should-not-crash-expected.txt: Added.
* fast/html/font-face-empty-should-not-crash.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (115971 => 115972)


--- trunk/LayoutTests/ChangeLog	2012-05-03 14:45:12 UTC (rev 115971)
+++ trunk/LayoutTests/ChangeLog	2012-05-03 15:11:27 UTC (rev 115972)
@@ -1,3 +1,13 @@
+2012-05-03  Caio Marcelo de Oliveira Filho  <[email protected]>
+
+        Remove extra checks for empty string when parsing CSS value
+        https://bugs.webkit.org/show_bug.cgi?id=85480
+
+        Reviewed by Alexis Menard.
+
+        * fast/html/font-face-empty-should-not-crash-expected.txt: Added.
+        * fast/html/font-face-empty-should-not-crash.html: Added.
+
 2012-05-03  Arpita Bahuguna  <[email protected]>
 
         Broken handling of pseudo-elements in selectors API

Added: trunk/LayoutTests/fast/html/font-face-empty-should-not-crash-expected.txt (0 => 115972)


--- trunk/LayoutTests/fast/html/font-face-empty-should-not-crash-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/html/font-face-empty-should-not-crash-expected.txt	2012-05-03 15:11:27 UTC (rev 115972)
@@ -0,0 +1 @@
+Test passes if it does not crash.

Added: trunk/LayoutTests/fast/html/font-face-empty-should-not-crash.html (0 => 115972)


--- trunk/LayoutTests/fast/html/font-face-empty-should-not-crash.html	                        (rev 0)
+++ trunk/LayoutTests/fast/html/font-face-empty-should-not-crash.html	2012-05-03 15:11:27 UTC (rev 115972)
@@ -0,0 +1,13 @@
+<!doctype html>
+<html>
+<head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+</head>
+<body>
+Test passes if it does not crash.
+<font face=""></font>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (115971 => 115972)


--- trunk/Source/WebCore/ChangeLog	2012-05-03 14:45:12 UTC (rev 115971)
+++ trunk/Source/WebCore/ChangeLog	2012-05-03 15:11:27 UTC (rev 115972)
@@ -1,3 +1,28 @@
+2012-05-03  Caio Marcelo de Oliveira Filho  <[email protected]>
+
+        Remove extra checks for empty string when parsing CSS value
+        https://bugs.webkit.org/show_bug.cgi?id=85480
+
+        Reviewed by Alexis Menard.
+
+        Each parse value helper function was checking whether the value string was empty. For the
+        common case this check is already done by StylePropertySet::setProperty(). So this patch
+        make CSSParser::parseValue() assume the value string is not empty, and fix the other two
+        clients.
+
+        Test: fast/html/font-face-empty-should-not-crash.html
+
+        * css/CSSParser.cpp:
+        (WebCore::parseColorValue): Replace the string empty check by an ASSERT() to document
+        function's expectations.
+        (WebCore::parseSimpleLengthValue): Ditto.
+        (WebCore::parseKeywordValue): Ditto.
+        (WebCore::CSSParser::parseFontFaceValue): This will be covered by the added test.
+        (WebCore::CSSParser::parseValue):
+        * css/WebKitCSSMatrix.cpp:
+        (WebCore::WebKitCSSMatrix::setMatrixValue): This is already covered by
+        transforms/cssmatrix-2d-interface.xhtml.
+
 2012-05-03  Arpita Bahuguna  <[email protected]>
 
         Broken handling of pseudo-elements in selectors API

Modified: trunk/Source/WebCore/css/CSSParser.cpp (115971 => 115972)


--- trunk/Source/WebCore/css/CSSParser.cpp	2012-05-03 14:45:12 UTC (rev 115971)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2012-05-03 15:11:27 UTC (rev 115972)
@@ -362,9 +362,8 @@
 
 static bool parseColorValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
 {
+    ASSERT(!string.isEmpty());
     bool strict = isStrictParserMode(cssParserMode);
-    if (!string.length())
-        return false;
     if (!isColorPropertyID(propertyId))
         return false;
     CSSParserString cssString;
@@ -442,13 +441,11 @@
 
 static bool parseSimpleLengthValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
 {
+    ASSERT(!string.isEmpty());
     bool acceptsNegativeNumbers;
     bool strict = isStrictParserMode(cssParserMode);
     unsigned length = string.length();
 
-    if (!length)
-        return false;
-
     double number;
     bool ok;
     CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
@@ -933,8 +930,7 @@
 
 static bool parseKeywordValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important)
 {
-    if (string.isEmpty())
-        return false;
+    ASSERT(!string.isEmpty());
 
     if (!isKeywordPropertyID(propertyId))
         return false;
@@ -963,6 +959,8 @@
 
 PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& string)
 {
+    if (string.isEmpty())
+        return 0;
     RefPtr<StylePropertySet> dummyStyle = StylePropertySet::create();
     if (!parseValue(dummyStyle.get(), CSSPropertyFontFamily, string, false, CSSQuirksMode, 0))
         return 0;
@@ -971,6 +969,7 @@
 
 bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetInternal* contextStyleSheet)
 {
+    ASSERT(!string.isEmpty());
     if (parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode))
         return true;
     if (parseColorValue(declaration, propertyID, string, important, cssParserMode))

Modified: trunk/Source/WebCore/css/WebKitCSSMatrix.cpp (115971 => 115972)


--- trunk/Source/WebCore/css/WebKitCSSMatrix.cpp	2012-05-03 14:45:12 UTC (rev 115971)
+++ trunk/Source/WebCore/css/WebKitCSSMatrix.cpp	2012-05-03 15:11:27 UTC (rev 115972)
@@ -52,6 +52,9 @@
 
 void WebKitCSSMatrix::setMatrixValue(const String& string, ExceptionCode& ec)
 {
+    if (string.isEmpty())
+        return;
+
     RefPtr<StylePropertySet> styleDeclaration = StylePropertySet::create();
     if (CSSParser::parseValue(styleDeclaration.get(), CSSPropertyWebkitTransform, string, true, CSSStrictMode, 0)) {
         // Convert to TransformOperations. This can fail if a property
@@ -80,7 +83,7 @@
 
         // set the matrix
         m_matrix = t;
-    } else if (!string.isEmpty()) // There is something there but parsing failed
+    } else // There is something there but parsing failed.
         ec = SYNTAX_ERR;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to