Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/283166

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(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/66/283166/1

diff --git a/MathMathML.php b/MathMathML.php
index 6d8f6a8..17b7e44 100644
--- a/MathMathML.php
+++ b/MathMathML.php
@@ -338,11 +338,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
@@ -350,7 +349,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
@@ -381,7 +382,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..27c35b2 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: newchange
Gerrit-Change-Id: I148433657848fdc74889fcaf6d883078c46a4006
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>

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

Reply via email to