jenkins-bot has submitted this change and it was merged.

Change subject: Ensure use of ; to seperate svg styles
......................................................................


Ensure use of ; to seperate svg styles

It was reported that under certain circumstances a semicolon was
missing from the SVG style.

Bug: T132563
Change-Id: I148433657848fdc74889fcaf6d883078c46a4006
---
M MathMathML.php
M tests/MathMathMLTest.php
2 files changed, 19 insertions(+), 5 deletions(-)

Approvals:
  Mobrovac: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/MathMathML.php b/MathMathML.php
index 64fe5d7..2dd091f 100644
--- a/MathMathML.php
+++ b/MathMathML.php
@@ -339,11 +339,10 @@
        /**
         * Helper function to correct the style information for a
         * linked SVG image.
-        * @param string $svg SVG-image data
         * @param string $style current style information to be updated
         */
-       public function correctSvgStyle( $svg, &$style ) {
-               if ( preg_match( '/style="([^"]*)"/', $svg, $styles ) ) {
+       public function correctSvgStyle( &$style ) {
+               if ( preg_match( '/style="([^"]*)"/', $this->getSvg(), $styles 
) ) {
                        $style .= ' ' . $styles[1]; // merge styles
                        if ( $this->getMathStyle() === 'display' ) {
                                // TODO: Improve style cleaning
@@ -351,7 +350,9 @@
                                        
'/margin\-(left|right)\:\s*\d+(\%|in|cm|mm|em|ex|pt|pc|px)\;/', '', $style
                                );
                        }
-                       $style = preg_replace( 
'/position:\s*absolute;\s*left:\s*0px;/', '', $style );
+                       $style = trim( preg_replace( 
'/position:\s*absolute;\s*left:\s*0px;/', '', $style ),
+                               "; \t\n\r\0\x0B" ) .'; ';
+
                }
                // TODO: Figure out if there is a way to construct
                // a SVGReader from a string that represents the SVG
@@ -382,7 +383,7 @@
                        $class = $classOverride;
                }
                if ( ! $this->mathoidStyle ) {
-                       $this->correctSvgStyle( $this->getSvg(), 
$this->mathoidStyle );
+                       $this->correctSvgStyle( $this->mathoidStyle );
                }
                // TODO: move the common styles to the global stylesheet!
                $style = 'background-image: url(\''. $url .
diff --git a/tests/MathMathMLTest.php b/tests/MathMathMLTest.php
index 3283da5..745c449 100644
--- a/tests/MathMathMLTest.php
+++ b/tests/MathMathMLTest.php
@@ -120,6 +120,19 @@
                $this->assertContains( '.png', $res );
        }
 
+       /**
+        * @covers MathMathML::correctSvgStyle
+        * @see https://phabricator.wikimedia.org/T132563
+        */
+       public function testMathMLStyle() {
+               $m = new MathMathML();
+               $m->setSvg( 'style="vertical-align:-.505ex" height="2.843ex" 
width="28.527ex"' );
+               $style = '';
+               $m->correctSvgStyle( $style );
+               $this->assertEquals( 'vertical-align:-.505ex; height: 2.843ex; 
width: 28.527ex;', $style );
+               $m->setSvg( 'style=" vertical-align:-.505ex; \n" 
height="2.843ex" width="28.527ex"' );
+               $this->assertEquals( 'vertical-align:-.505ex; height: 2.843ex; 
width: 28.527ex;', $style );
+       }
 }
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/283166
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I148433657848fdc74889fcaf6d883078c46a4006
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: TheDJ <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to