Merge "Fix TitlePermissionTest failures due to test leakage"
[lhc/web/wiklou.git] / includes / media / SVGMetadataExtractor.php
index 2cf4d23..e52bf0b 100644 (file)
@@ -22,7 +22,7 @@
  * @author "Derk-Jan Hartman <hartman _at_ videolan d0t org>"
  * @author Brion Vibber
  * @copyright Copyright © 2010-2010 Brion Vibber, Derk-Jan Hartman
- * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
+ * @license GPL-2.0-or-later
  */
 
 /**
@@ -58,8 +58,6 @@ class SVGReader {
        private $languagePrefixes = [];
 
        /**
-        * Constructor
-        *
         * Creates an SVGReader drawing from the source provided
         * @param string $source URI from which to read
         * @throws MWException|Exception
@@ -108,17 +106,17 @@ class SVGReader {
                // Because we cut off the end of the svg making an invalid one. Complicated
                // try catch thing to make sure warnings get restored. Seems like there should
                // be a better way.
-               MediaWiki\suppressWarnings();
+               Wikimedia\suppressWarnings();
                try {
                        $this->read();
                } catch ( Exception $e ) {
                        // Note, if this happens, the width/height will be taken to be 0x0.
                        // Should we consider it the default 512x512 instead?
-                       MediaWiki\restoreWarnings();
+                       Wikimedia\restoreWarnings();
                        libxml_disable_entity_loader( $oldDisable );
                        throw $e;
                }
-               MediaWiki\restoreWarnings();
+               Wikimedia\restoreWarnings();
                libxml_disable_entity_loader( $oldDisable );
        }
 
@@ -327,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] );
@@ -382,7 +380,11 @@ class SVGReader {
                        '' => 1.0, // "User units" pixels by default
                ];
                $matches = [];
-               if ( preg_match( '/^\s*(\d+(?:\.\d+)?)(em|ex|px|pt|pc|cm|mm|in|%|)\s*$/', $length, $matches ) ) {
+               if ( preg_match(
+                       '/^\s*([-+]?\d*(?:\.\d+|\d+)(?:[Ee][-+]?\d+)?)\s*(em|ex|px|pt|pc|cm|mm|in|%|)\s*$/',
+                       $length,
+                       $matches
+               ) ) {
                        $length = floatval( $matches[1] );
                        $unit = $matches[2];
                        if ( $unit == '%' ) {