From 6a68fad159d557704bd645fa1aa44df17b453eed Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Thu, 14 Aug 2014 12:28:36 -0400 Subject: [PATCH] Protect MathML from Tidy MediaWiki installations that use the setting $wgUseTidy = true; are unable to output MathML since the well defined MathML elements are filtered out by Tidy. This was reported as http://sourceforge.net/p/tidy/patches/84/ . This change hides MathML blocks from Tidy. Bug: 66516 Change-Id: Ib48b91238c3eddd6a86b62f6ce57801d7058f0d8 --- includes/parser/MWTidy.php | 4 +++- tests/parser/parserTests.txt | 8 ++++++++ tests/phpunit/includes/parser/TidyTest.php | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/includes/parser/MWTidy.php b/includes/parser/MWTidy.php index a108d2beea..b310862f3f 100644 --- a/includes/parser/MWTidy.php +++ b/includes/parser/MWTidy.php @@ -65,7 +65,9 @@ class MWTidyWrapper { // ...and markers $wrappedtext = preg_replace_callback( '/\<\\/?mw:toc\>/', array( &$this, 'replaceCallback' ), $wrappedtext ); - + // ... and tags + $wrappedtext = preg_replace_callback( '/\/s', + array( &$this, 'replaceCallback' ), $wrappedtext ); // Modify inline Microdata and elements so they say and so // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', '-wiki-tags without Extension:Math enabled +!! wikitext + +!! html+tidy +

<math><img src="some evil external link"><script>some_evil_javascript();</script></math>

+!! end + ### ### Parser hooks (see tests/parser/parserTestsParserHook.php for the extension) ### diff --git a/tests/phpunit/includes/parser/TidyTest.php b/tests/phpunit/includes/parser/TidyTest.php index 12aac6916c..7b2a1da72a 100644 --- a/tests/phpunit/includes/parser/TidyTest.php +++ b/tests/phpunit/includes/parser/TidyTest.php @@ -26,6 +26,24 @@ class TidyTest extends MediaWikiTestCase { } public function provideTestWrapping() { + $testMathML = <<<'MathML' + + + a + + + x + 2 + + + + b + + x + + + c + + +MathML; return array( array( 'foo', @@ -40,6 +58,7 @@ class TidyTest extends MediaWikiTestCase { array( 'foo', 'foo', ' should survive tidy' ), array( "\nfoo", 'foo', ' should survive tidy' ), array( "\nfoo", 'foo', ' should survive tidy' ), + array( $testMathML , $testMathML, ' should survive tidy' ), ); } } -- 2.20.1