From 25c293cadc3f8753a08a597407daefd5f8079f46 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Sat, 11 Aug 2018 00:12:36 +0200 Subject: [PATCH] SVG: Allow , as separator in viewBox attribute value The viewBox attribute of the 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 | 2 +- tests/phpunit/data/media/comma_separated_viewbox.svg | 3 +++ .../includes/media/SVGMetadataExtractorTest.php | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/data/media/comma_separated_viewbox.svg diff --git a/includes/media/SVGMetadataExtractor.php b/includes/media/SVGMetadataExtractor.php index ee467b084f..e52bf0b26a 100644 --- a/includes/media/SVGMetadataExtractor.php +++ b/includes/media/SVGMetadataExtractor.php @@ -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 index 0000000000..9e7329d249 --- /dev/null +++ b/tests/phpunit/data/media/comma_separated_viewbox.svg @@ -0,0 +1,3 @@ + + + diff --git a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php index c258b6a745..7aef246fcc 100644 --- a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php +++ b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php @@ -134,6 +134,16 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase { 'translations' => [] ], ], + [ + "$base/comma_separated_viewbox.svg", + [ + 'width' => 512, + 'height' => 594, + 'originalWidth' => '100%', + 'originalHeight' => '100%', + 'translations' => [] + ], + ], ]; } -- 2.20.1