Title: [122978] trunk
Revision
122978
Author
k...@webkit.org
Date
2012-07-18 08:42:40 -0700 (Wed, 18 Jul 2012)

Log Message

SVG CSS property types with <number> don't support exponents
https://bugs.webkit.org/show_bug.cgi?id=52542

Reviewed by Nikolas Zimmermann.

Source/WebCore:

Parse numbers in SVG presentation attributes with SVG parser to support scientific notations.
The SVG parser is already well tested and has some extra checks for edge like protection from
overflow.

The patch is based upon a patch of Bear Travis.

Test: svg/css/scientific-numbers.html

* css/CSSParser.cpp:
(WebCore::CSSParser::lex): Use SVG parser to parse numbers of SVG attributes.
* svg/SVGParserUtilities.cpp:
(WebCore::parseSVGNumber): Added accessor to call from CSSParser with double value.
(WebCore):
* svg/SVGParserUtilities.h:
(WebCore):

LayoutTests:

Test scientific number values on SVG presentation attributes.

* svg/css/scientific-numbers-expected.txt: Added.
* svg/css/scientific-numbers.html: Added.
* svg/css/script-tests/scientific-numbers.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (122977 => 122978)


--- trunk/LayoutTests/ChangeLog	2012-07-18 15:39:19 UTC (rev 122977)
+++ trunk/LayoutTests/ChangeLog	2012-07-18 15:42:40 UTC (rev 122978)
@@ -1,3 +1,16 @@
+2012-07-18  Dirk Schulze  <k...@webkit.org>
+
+        SVG CSS property types with <number> don't support exponents
+        https://bugs.webkit.org/show_bug.cgi?id=52542
+
+        Reviewed by Nikolas Zimmermann.
+
+        Test scientific number values on SVG presentation attributes.
+
+        * svg/css/scientific-numbers-expected.txt: Added.
+        * svg/css/scientific-numbers.html: Added.
+        * svg/css/script-tests/scientific-numbers.js: Added.
+
 2012-07-18  Douglas Stockwell  <dstockw...@chromium.org>
 
         WebCore::StylePropertySet::addParsedProperties - crash

Added: trunk/LayoutTests/svg/css/scientific-numbers-expected.txt (0 => 122978)


--- trunk/LayoutTests/svg/css/scientific-numbers-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/svg/css/scientific-numbers-expected.txt	2012-07-18 15:42:40 UTC (rev 122978)
@@ -0,0 +1,115 @@
+Test scientific numbers on values for SVG presentation attributes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Test positive exponent values with 'e'
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+
+Test positive exponent values with 'E'
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+
+Test negative exponent values with 'e'
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+
+Test negative exponent values with 'E'
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+
+Test negative numbers with exponents
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "-50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "-50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "-50px"
+
+Test if value and 'em' still works
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50em"
+
+Test if value and 'ex' still works
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50ex"
+
+Trailing and leading whitespaces
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "50px"
+
+Test behavior on overflow
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+
+Invalid values
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS getComputedStyle(text).baselineShift is "baseline"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/svg/css/scientific-numbers.html (0 => 122978)


--- trunk/LayoutTests/svg/css/scientific-numbers.html	                        (rev 0)
+++ trunk/LayoutTests/svg/css/scientific-numbers.html	2012-07-18 15:42:40 UTC (rev 122978)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src=""
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/svg/css/script-tests/scientific-numbers.js (0 => 122978)


--- trunk/LayoutTests/svg/css/script-tests/scientific-numbers.js	                        (rev 0)
+++ trunk/LayoutTests/svg/css/script-tests/scientific-numbers.js	2012-07-18 15:42:40 UTC (rev 122978)
@@ -0,0 +1,95 @@
+description("Test scientific numbers on <length> values for SVG presentation attributes.")
+createSVGTestCase();
+
+var text = createSVGElement("text");
+text.setAttribute("id", "text");
+text.setAttribute("x", "100px");
+text.setAttribute("y", "100px");
+rootSVGElement.appendChild(text);
+
+function test(valueString, expectedValue) {
+	// Reset baseline-shift to baseline.
+	text.setAttribute("baseline-shift", "baseline");
+	shouldBeEqualToString("getComputedStyle(text).baselineShift", "baseline");
+
+	// Run test
+	text.setAttribute("baseline-shift", valueString);
+	shouldBeEqualToString("getComputedStyle(text).baselineShift", expectedValue);
+}
+
+debug("");
+debug("Test positive exponent values with 'e'");
+test(".5e2", "50px");
+test("5e1", "50px");
+test("0.5e2", "50px");
+test("+.5e2", "50px");
+test("+5e1", "50px");
+test("+0.5e2", "50px");
+test(".5e+2", "50px");
+test("5e+1", "50px");
+test("0.5e+2", "50px");
+
+debug("");
+debug("Test positive exponent values with 'E'");
+test(".5E2", "50px");
+test("5E1", "50px");
+test("0.5E2", "50px");
+test("+.5E2", "50px");
+test("+5E1", "50px");
+test("+0.5E2", "50px");
+test(".5E+2", "50px");
+test("5E+1", "50px");
+test("0.5E+2", "50px");
+
+debug("");
+debug("Test negative exponent values with 'e'");
+test("5000e-2", "50px");
+test("500e-1", "50px");
+test("+5000e-2", "50px");
+test("+500e-1", "50px");
+test("+5000e-2px", "50px");
+test("+500e-1px", "50px");
+
+debug("");
+debug("Test negative exponent values with 'E'");
+test("5000E-2", "50px");
+test("500E-1", "50px");
+test("+5000E-2", "50px");
+test("+500E-1", "50px");
+test("+5000.00E-2px", "50px");
+test("+500E-1px", "50px");
+
+debug("");
+debug("Test negative numbers with exponents");
+test("-.5e2px", "-50px");
+test("-0.5e2px", "-50px");
+test("-500e-1px", "-50px");
+
+debug("");
+debug("Test if value and 'em' still works");
+test("50em", "50em");
+
+debug("");
+debug("Test if value and 'ex' still works");
+test("50ex", "50ex");
+
+debug("");
+debug("Trailing and leading whitespaces");
+test("       5e1", "50px");
+test("5e1      ", "50px");
+
+debug("");
+debug("Test behavior on overflow");
+test("2E+500", "baseline");
+test("-2E+500", "baseline");
+
+debug("");
+debug("Invalid values");
+test("50e0.0", "baseline");
+test("50 e0", "baseline");
+test("50e 0", "baseline");
+test("50.e0", "baseline");
+
+var successfullyParsed = true;
+
+completeTest();
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (122977 => 122978)


--- trunk/Source/WebCore/ChangeLog	2012-07-18 15:39:19 UTC (rev 122977)
+++ trunk/Source/WebCore/ChangeLog	2012-07-18 15:42:40 UTC (rev 122978)
@@ -1,3 +1,27 @@
+2012-07-18  Dirk Schulze  <k...@webkit.org>
+
+        SVG CSS property types with <number> don't support exponents
+        https://bugs.webkit.org/show_bug.cgi?id=52542
+
+        Reviewed by Nikolas Zimmermann.
+
+        Parse numbers in SVG presentation attributes with SVG parser to support scientific notations.
+        The SVG parser is already well tested and has some extra checks for edge like protection from
+        overflow.
+        
+        The patch is based upon a patch of Bear Travis.
+
+        Test: svg/css/scientific-numbers.html
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::lex): Use SVG parser to parse numbers of SVG attributes.
+        * svg/SVGParserUtilities.cpp:
+        (WebCore::parseSVGNumber): Added accessor to call from CSSParser with double value.
+        (WebCore):
+        * svg/SVGParserUtilities.h:
+        (WebCore):
+
+
 2012-07-18  Pavel Feldman  <pfeld...@chromium.org>
 
         Web Inspector: beautify the paused in debugger message, make it configurable from the front-end.

Modified: trunk/Source/WebCore/css/CSSParser.cpp (122977 => 122978)


--- trunk/Source/WebCore/css/CSSParser.cpp	2012-07-18 15:39:19 UTC (rev 122977)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2012-07-18 15:42:40 UTC (rev 122978)
@@ -69,6 +69,7 @@
 #include "Rect.h"
 #include "RenderTheme.h"
 #include "RuntimeEnabledFeatures.h"
+#include "SVGParserUtilities.h"
 #include "Settings.h"
 #include "ShadowValue.h"
 #include "StylePropertySet.h"
@@ -8967,8 +8968,29 @@
             break;
         }
 
-        yylval->number = charactersToDouble(m_tokenStart, m_currentCharacter - m_tokenStart);
-
+#if ENABLE(SVG)
+        // Use SVG parser for numbers on SVG presentation attributes.
+        if (m_context.mode == SVGAttributeMode) {
+            // We need to take care of units like 'em' or 'ex'.
+            UChar* currentCharacter = m_currentCharacter;
+            if (isASCIIAlphaCaselessEqual(*currentCharacter, 'e')) {
+                ASSERT(currentCharacter - m_tokenStart > 0);
+                ++currentCharacter;
+                if (*currentCharacter == '-' || *currentCharacter == '+' || isASCIIDigit(*currentCharacter)) {
+                    ++currentCharacter;
+                    while (isASCIIDigit(*currentCharacter))
+                        ++currentCharacter;
+                    // Use FLOATTOKEN if the string contains exponents.
+                    dotSeen = true;
+                    m_currentCharacter = currentCharacter;
+                }
+            }
+            if (!parseSVGNumber(m_tokenStart, currentCharacter - m_tokenStart, yylval->number))
+                break;
+        } else
+#endif
+            yylval->number = charactersToDouble(m_tokenStart, m_currentCharacter - m_tokenStart);
+ 
         // Type of the function.
         if (isIdentifierStart()) {
             UChar* type = m_currentCharacter;

Modified: trunk/Source/WebCore/svg/SVGParserUtilities.cpp (122977 => 122978)


--- trunk/Source/WebCore/svg/SVGParserUtilities.cpp	2012-07-18 15:39:19 UTC (rev 122977)
+++ trunk/Source/WebCore/svg/SVGParserUtilities.cpp	2012-07-18 15:42:40 UTC (rev 122978)
@@ -142,6 +142,13 @@
     return true;
 }
 
+bool parseSVGNumber(UChar*& begin, size_t length, double& number)
+{
+    const UChar* ptr = begin;
+    const UChar* end = ptr + length;
+    return genericParseNumber(ptr, end, number, false);
+}
+
 bool parseNumber(const UChar*& ptr, const UChar* end, float& number, bool skip) 
 {
     return genericParseNumber(ptr, end, number, skip);

Modified: trunk/Source/WebCore/svg/SVGParserUtilities.h (122977 => 122978)


--- trunk/Source/WebCore/svg/SVGParserUtilities.h	2012-07-18 15:39:19 UTC (rev 122977)
+++ trunk/Source/WebCore/svg/SVGParserUtilities.h	2012-07-18 15:42:40 UTC (rev 122978)
@@ -33,6 +33,7 @@
 class FloatRect;
 class SVGPointList;
 
+bool parseSVGNumber(UChar*& ptr, size_t length, double& number);
 bool parseNumber(const UChar*& ptr, const UChar* end, float& number, bool skip = true);
 bool parseNumberFromString(const String&, float& number, bool skip = true);
 bool parseNumberOptionalNumber(const String& s, float& h, float& v);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to