Bug 946529 - Fix parsing of numbers with scientific notation in SVG; r=longsonr a=bkerensa
authorBrian Birtles <birtles@gmail.com>
Thu, 12 Dec 2013 11:02:17 +0900
changeset 167683 6bbfc4a81d0672fd28bc3d816a1ad5188aeab1e7
parent 167682 3cd5bb2dddcde84e3cf6a8affa191c239c084653
child 167684 4418ee14f23944b2ec8130e1bd8b6f46d0710d62
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr, bkerensa
bugs946529
milestone27.0
Bug 946529 - Fix parsing of numbers with scientific notation in SVG; r=longsonr a=bkerensa
content/svg/content/src/SVGContentUtils.cpp
content/svg/content/test/Makefile.in
content/svg/content/test/test_lengthParsing.html
--- a/content/svg/content/src/SVGContentUtils.cpp
+++ b/content/svg/content/src/SVGContentUtils.cpp
@@ -456,21 +456,21 @@ SVGContentUtils::ParseNumber(const nsASt
 
     mozilla::RangedPtr<const PRUnichar> expIter(iter);
 
     ++expIter;
     if (expIter != end) {
       expSign = *expIter == '-' ? -1 : 1;
       if (*expIter == '-' || *expIter == '+') {
         ++expIter;
-        if (expIter != end && IsDigit(*expIter)) {
-          // At this point we're sure this is an exponent
-          // and not the start of a unit such as em or ex.
-          gotE = true;
-        }
+      }
+      if (expIter != end && IsDigit(*expIter)) {
+        // At this point we're sure this is an exponent
+        // and not the start of a unit such as em or ex.
+        gotE = true;
       }
     }
 
     if (gotE) {
       iter = expIter;
       do {
         exponent = 10 * exponent + DecimalDigitValue(*iter);
         ++iter;
--- a/content/svg/content/test/Makefile.in
+++ b/content/svg/content/test/Makefile.in
@@ -30,16 +30,17 @@ MOCHITEST_FILES = \
 		test_fragments.html \
 		fragments-helper.svg \
 		getCTM-helper.svg \
 		test_getCTM.html \
 		test_getElementById.xhtml \
 		test_getSubStringLength.xhtml \
 		getSubStringLength-helper.svg \
 		test_hasFeature.xhtml \
+		test_lengthParsing.html \
 		$(filter disabled-for-intermittent-failures--bug-701060, test_lang.xhtml) \
 		test_nonAnimStrings.xhtml \
 		test_non-scaling-stroke.html \
 		test_pathAnimInterpolation.xhtml \
 		test_pathSeg.xhtml \
 		test_pointAtLength.xhtml \
 		test_pointer-events-1a.xhtml \
 		test_pointer-events-1b.xhtml \
new file mode 100644
--- /dev/null
+++ b/content/svg/content/test/test_lengthParsing.html
@@ -0,0 +1,77 @@
+<!doctype html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=946529
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test transform parsing</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=946529">Mozilla Bug 946529</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  <svg width="100%" height="1" id="svg">
+    <rect id="rect"/>
+  </svg>
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+// Test cases
+checkParseOk("", 0);
+checkParseOk("-.1", -0.1);
+checkParseOk("1e1", 10);
+checkParseOk("1em", 1, "em");
+checkParseOk("1ex", 1, "ex");
+checkParseOk("1e1em", 10, "em");
+checkParseOk("1E+2", 100);
+checkParseOk(".1e-2", 0.001);
+
+// Fail cases
+checkParseFail("1e");
+checkParseFail("1 e");
+checkParseFail("1 em");
+checkParseFail("1ee");
+
+function checkParseOk(spec, valueInUnits, units) {
+  var rect = document.getElementById("rect");
+
+  // Clear previous value
+  rect.removeAttribute("x");
+  rect.setAttribute("x", spec);
+
+  // Check number part
+  const tolerance = 1 / 65535;
+  var actual = rect.x.baseVal.valueInSpecifiedUnits;
+  ok(Math.abs(actual - valueInUnits) < tolerance,
+     spec + ' (value) - got ' + actual + ', expected ' + valueInUnits);
+
+  // Check unit part
+  var unitMapping = {
+    "unknown": SVGLength.SVG_LENGTHTYPE_UNKNOWN,
+    "": SVGLength.SVG_LENGTHTYPE_NUMBER,
+    "%": SVGLength.SVG_LENGTHTYPE_PERCENTAGE,
+    "em": SVGLength.SVG_LENGTHTYPE_EMS,
+    "ex": SVGLength.SVG_LENGTHTYPE_EXS,
+    "px": SVGLength.SVG_LENGTHTYPE_PX,
+    "cm": SVGLength.SVG_LENGTHTYPE_CM,
+    "mm": SVGLength.SVG_LENGTHTYPE_MM,
+    "in": SVGLength.SVG_LENGTHTYPE_IN,
+    "pt": SVGLength.SVG_LENGTHTYPE_PT,
+    "pc": SVGLength.SVG_LENGTHTYPE_PC
+  };
+  if (typeof units == "undefined") {
+    units = "";
+  }
+  ise(rect.x.baseVal.unitType, unitMapping[units], spec + " (unit)");
+}
+
+function checkParseFail(spec) {
+  checkParseOk(spec, 0);
+}
+</script>
+</pre>
+</body>
+</html>