Reviewed by Darin.
authorrwlbuis <rwlbuis@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Jul 2006 07:46:00 +0000 (07:46 +0000)
committerrwlbuis <rwlbuis@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Jul 2006 07:46:00 +0000 (07:46 +0000)
        http://bugzilla.opendarwin.org/show_bug.cgi?id=9938
        Fix viewBox issues in Hixie's test

        Do a more accurate and quicker job of parsing the viewBox
        attribute. Handle properly on negative width/height and
        invalid syntax in general.

        * ksvg2/svg/SVGFitToViewBox.cpp:
        (SVGFitToViewBox::parseViewBox):

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

LayoutTests/ChangeLog
LayoutTests/svg/custom/invalid-viewbox1-expected.checksum [new file with mode: 0644]
LayoutTests/svg/custom/invalid-viewbox1-expected.png [new file with mode: 0644]
LayoutTests/svg/custom/invalid-viewbox1-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/invalid-viewbox1.svg [new file with mode: 0644]
LayoutTests/svg/custom/invalid-viewbox2-expected.checksum [new file with mode: 0644]
LayoutTests/svg/custom/invalid-viewbox2-expected.png [new file with mode: 0644]
LayoutTests/svg/custom/invalid-viewbox2-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/invalid-viewbox2.svg [new file with mode: 0644]
WebCore/ChangeLog
WebCore/ksvg2/svg/SVGFitToViewBox.cpp

index 78d32ab8ab490968c54d873981169bf6d90c4130..eb617348659fafccd1ebca52dc12ee1dafb01052 100644 (file)
@@ -1,3 +1,22 @@
+2006-07-27  Rob Buis  <buis@kde.org
+
+        Reviewed by Darin.
+
+        Add some tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=9938
+        Specifically the testcases are:
+
+        http://hixie.ch/tests/adhoc/svg/error/010.xml
+        http://hixie.ch/tests/adhoc/svg/error/011.xml
+
+        * svg/custom/invalid-viewbox1-expected.checksum: Added.
+        * svg/custom/invalid-viewbox1-expected.png: Added.
+        * svg/custom/invalid-viewbox1-expected.txt: Added.
+        * svg/custom/invalid-viewbox1.svg: Added.
+        * svg/custom/invalid-viewbox2-expected.checksum: Added.
+        * svg/custom/invalid-viewbox2-expected.png: Added.
+        * svg/custom/invalid-viewbox2-expected.txt: Added.
+        * svg/custom/invalid-viewbox2.svg: Added.
+
 2006-07-27  Eric Seidel  <eric@eseidel.com>
 
         Reviewed by ap.
diff --git a/LayoutTests/svg/custom/invalid-viewbox1-expected.checksum b/LayoutTests/svg/custom/invalid-viewbox1-expected.checksum
new file mode 100644 (file)
index 0000000..843abe1
--- /dev/null
@@ -0,0 +1 @@
+f367f0d6384e33430dd99829730e45bb
\ No newline at end of file
diff --git a/LayoutTests/svg/custom/invalid-viewbox1-expected.png b/LayoutTests/svg/custom/invalid-viewbox1-expected.png
new file mode 100644 (file)
index 0000000..064c6b0
Binary files /dev/null and b/LayoutTests/svg/custom/invalid-viewbox1-expected.png differ
diff --git a/LayoutTests/svg/custom/invalid-viewbox1-expected.txt b/LayoutTests/svg/custom/invalid-viewbox1-expected.txt
new file mode 100644 (file)
index 0000000..36ba3a8
--- /dev/null
@@ -0,0 +1,7 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+    KCanvasContainer {svg} at (0,0) size 1x1
+      KCanvasItem {rect} at (0,0) size 1x1 [fill={[type=SOLID] [color=#FF0000]}] [data="M0.00,0.00L1.00,0.00L1.00,1.00L0.00,1.00"]
+      RenderSVGText {text} at (0,0) size 785x23
+        RenderText {#text} at (0,0) size 294x23
+          text run at (0,0) width 294: "There should be no red on this page."
diff --git a/LayoutTests/svg/custom/invalid-viewbox1.svg b/LayoutTests/svg/custom/invalid-viewbox1.svg
new file mode 100644 (file)
index 0000000..e696277
--- /dev/null
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1 1"> <!-- five values on this list is non-conformant, so this should be unsupported and therefore ignored. -->
+ <rect x="0" y="0" width="1" height="1" fill="red"/>
+ <text x="10" y="30" font-size="20" fill="blue">There should be no red on this page.</text>
+</svg>
diff --git a/LayoutTests/svg/custom/invalid-viewbox2-expected.checksum b/LayoutTests/svg/custom/invalid-viewbox2-expected.checksum
new file mode 100644 (file)
index 0000000..843abe1
--- /dev/null
@@ -0,0 +1 @@
+f367f0d6384e33430dd99829730e45bb
\ No newline at end of file
diff --git a/LayoutTests/svg/custom/invalid-viewbox2-expected.png b/LayoutTests/svg/custom/invalid-viewbox2-expected.png
new file mode 100644 (file)
index 0000000..064c6b0
Binary files /dev/null and b/LayoutTests/svg/custom/invalid-viewbox2-expected.png differ
diff --git a/LayoutTests/svg/custom/invalid-viewbox2-expected.txt b/LayoutTests/svg/custom/invalid-viewbox2-expected.txt
new file mode 100644 (file)
index 0000000..36ba3a8
--- /dev/null
@@ -0,0 +1,7 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+    KCanvasContainer {svg} at (0,0) size 1x1
+      KCanvasItem {rect} at (0,0) size 1x1 [fill={[type=SOLID] [color=#FF0000]}] [data="M0.00,0.00L1.00,0.00L1.00,1.00L0.00,1.00"]
+      RenderSVGText {text} at (0,0) size 785x23
+        RenderText {#text} at (0,0) size 294x23
+          text run at (0,0) width 294: "There should be no red on this page."
diff --git a/LayoutTests/svg/custom/invalid-viewbox2.svg b/LayoutTests/svg/custom/invalid-viewbox2.svg
new file mode 100644 (file)
index 0000000..944ed51
--- /dev/null
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0,, 1 1"> <!-- two commas is non-conformant, so this should be unsupported and therefore ignored. -->
+ <rect x="0" y="0" width="1" height="1" fill="red"/>
+ <text x="10" y="30" font-size="20" fill="blue">There should be no red on this page.</text>
+</svg>
index 43c0c4228df491f1a6824514c5e523a45505b049..8cd5d6516d2e47299cad35af0e4885f2b5709ae3 100644 (file)
@@ -1,3 +1,17 @@
+2006-07-27  Rob Buis  <buis@kde.org>
+
+        Reviewed by Darin.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=9938
+        Fix viewBox issues in Hixie's test
+
+        Do a more accurate and quicker job of parsing the viewBox
+        attribute. Handle properly on negative width/height and
+        invalid syntax in general.
+
+        * ksvg2/svg/SVGFitToViewBox.cpp:
+        (SVGFitToViewBox::parseViewBox):
+
 2006-07-27  Eric Seidel  <eric@eseidel.com>
 
         Reviewed by ap.
index d6b22695eaaff89ca115e5c0daacf317f9d21de4..75b660c6b9190e7f06b5811cb1d562ecef2fa2f5 100644 (file)
@@ -28,6 +28,7 @@
 #include "StringImpl.h"
 
 #include "SVGNames.h"
+#include "svgpathparser.h"
 #include "SVGRect.h"
 #include "SVGSVGElement.h"
 #include "SVGAnimatedRect.h"
@@ -69,16 +70,57 @@ SVGAnimatedPreserveAspectRatio *SVGFitToViewBox::preserveAspectRatio() const
 
 void SVGFitToViewBox::parseViewBox(StringImpl *str)
 {
-    // allow for viewbox def with ',' or whitespace
+    double x = 0, y = 0, w = 0, h = 0;
     DeprecatedString viewbox = String(str).deprecatedString();
-    DeprecatedStringList points = DeprecatedStringList::split(' ', viewbox.replace(',', ' ').simplifyWhiteSpace());
-
-    if (points.count() == 4) {
-        viewBox()->baseVal()->setX(points[0].toDouble());
-        viewBox()->baseVal()->setY(points[1].toDouble());
-        viewBox()->baseVal()->setWidth(points[2].toDouble());
-        viewBox()->baseVal()->setHeight(points[3].toDouble());
-    } else
+    const char *p = viewbox.latin1();
+    const char *end = p + viewbox.length();
+    const char *c = p;
+    p = parseCoord(c, x);
+    if (p == c)
+        goto bail_out;
+    if (*p == ',')
+        p++;
+    while (*p == ' ')
+        p++;
+
+    c = p;
+    p = parseCoord(c, y);
+    if (p == c)
+        goto bail_out;
+
+    if (*p == ',')
+        p++;
+    while (*p == ' ')
+        p++;
+
+    c = p;
+    p = parseCoord(c, w);
+    if(w < 0.0 || p == c) // check that width is positive
+        goto bail_out;
+    if (*p == ',')
+        p++;
+    while (*p == ' ')
+        p++;
+
+    c = p;
+    p = parseCoord(c, h);
+    if (h < 0.0 || p == c) // check that height is positive
+        goto bail_out;
+    if (*p == ',')
+        p++;
+    while (*p == ' ')
+        p++;
+
+    if (p < end) // nothing should come after the last, fourth number
+        goto bail_out;
+
+    viewBox()->baseVal()->setX(x);
+    viewBox()->baseVal()->setY(y);
+    viewBox()->baseVal()->setWidth(w);
+    viewBox()->baseVal()->setHeight(h);
+    return;
+
+bail_out:
         fprintf(stderr, "WARNING: Malformed viewbox string: %s (l: %i)", viewbox.ascii(), viewbox.length());
 }