SVG: Allow , as separator in viewBox attribute value
authorDerk-Jan Hartman <hartman.wiki@gmail.com>
Fri, 10 Aug 2018 22:12:36 +0000 (00:12 +0200)
committerDerk-Jan Hartman <hartman.wiki@gmail.com>
Fri, 10 Aug 2018 22:16:43 +0000 (00:16 +0200)
The viewBox attribute of the <svg> element allows both whitespace and
commas to be used as field separators.
https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute

Bug: T194192
Change-Id: Iae9be3e4fad3a8ffa411d7a76eee2f20cc39b718

includes/media/SVGMetadataExtractor.php
tests/phpunit/data/media/comma_separated_viewbox.svg [new file with mode: 0644]
tests/phpunit/includes/media/SVGMetadataExtractorTest.php

index ee467b0..e52bf0b 100644 (file)
@@ -325,7 +325,7 @@ class SVGReader {
 
                if ( $this->reader->getAttribute( 'viewBox' ) ) {
                        // min-x min-y width height
-                       $viewBox = preg_split( '/\s+/', trim( $this->reader->getAttribute( 'viewBox' ) ) );
+                       $viewBox = preg_split( '/\s*[\s,]\s*/', trim( $this->reader->getAttribute( 'viewBox' ) ) );
                        if ( count( $viewBox ) == 4 ) {
                                $viewWidth = $this->scaleSVGUnit( $viewBox[2] );
                                $viewHeight = $this->scaleSVGUnit( $viewBox[3] );
diff --git a/tests/phpunit/data/media/comma_separated_viewbox.svg b/tests/phpunit/data/media/comma_separated_viewbox.svg
new file mode 100644 (file)
index 0000000..9e7329d
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="100%" width="100%" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" viewBox=" 0, 0 ,349.46883 , 405.12272 ">
+</svg>
index c258b6a..7aef246 100644 (file)
@@ -134,6 +134,16 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase {
                                        'translations' => []
                                ],
                        ],
+                       [
+                               "$base/comma_separated_viewbox.svg",
+                               [
+                                       'width' => 512,
+                                       'height' => 594,
+                                       'originalWidth' => '100%',
+                                       'originalHeight' => '100%',
+                                       'translations' => []
+                               ],
+                       ],
                ];
        }