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
This commit is contained in:
physikerwelt 2016-04-13 08:30:48 -04:00 committed by Mobrovac
parent 0d55341ff9
commit 6b984122a1
2 changed files with 19 additions and 5 deletions

View File

@ -339,11 +339,10 @@ class MathMathML extends MathRenderer {
/**
* 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 @@ class MathMathML extends MathRenderer {
'/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 MathMathML extends MathRenderer {
$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 .

View File

@ -120,6 +120,19 @@ class MathMathMLTest extends MediaWikiTestCase {
$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 );
}
}
/**