MaxSem has uploaded a new change for review. https://gerrit.wikimedia.org/r/91902
Change subject: Fix Tidy quietly breaking TOC disabling ...................................................................... Fix Tidy quietly breaking TOC disabling The functionality was introduced in https://gerrit.wikimedia.org/r/80578 but doesn't work in presence if Tidy. Change-Id: Ibf96cc3bc94fac75fd92ec5b9205011fcb68f0c2 --- M includes/parser/Tidy.php A tests/phpunit/includes/parser/TidyTest.php 2 files changed, 49 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/02/91902/1 diff --git a/includes/parser/Tidy.php b/includes/parser/Tidy.php index 0625140..32b16aa 100644 --- a/includes/parser/Tidy.php +++ b/includes/parser/Tidy.php @@ -61,7 +61,10 @@ // Replace <mw:editsection> elements with placeholders $wrappedtext = preg_replace_callback( ParserOutput::EDITSECTION_REGEX, - array( &$this, 'replaceEditSectionLinksCallback' ), $text ); + array( &$this, 'replaceCallback' ), $text ); + // ...and <mw:toc> markers + $wrappedtext = preg_replace_callback( '/\<\\/?mw:toc\>/', + array( &$this, 'replaceCallback' ), $wrappedtext ); // Modify inline Microdata <link> and <meta> elements so they say <html-link> and <html-meta> so // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config @@ -80,7 +83,7 @@ * * @return string */ - function replaceEditSectionLinksCallback( $m ) { + function replaceCallback( $m ) { $marker = "{$this->mUniqPrefix}-item-{$this->mMarkerIndex}" . Parser::MARKER_SUFFIX; $this->mMarkerIndex++; $this->mTokens->setPair( $marker, $m[0] ); diff --git a/tests/phpunit/includes/parser/TidyTest.php b/tests/phpunit/includes/parser/TidyTest.php new file mode 100644 index 0000000..57a88b9 --- /dev/null +++ b/tests/phpunit/includes/parser/TidyTest.php @@ -0,0 +1,44 @@ +<?php + +/** + * @group Parser + */ +class TidyTest extends MediaWikiTestCase { + public function setUp() { + parent::setUp(); + $check = MWTidy::tidy( '' ); + if ( strpos( $check, '<!--' ) !== false ) { + $this->markTestSkipped( 'Tidy not found' ); + } + } + + /** + * @dataProvider provideTestWrapping + */ + public function testTidyWrapping( $expected, $text, $msg = '' ) { + $text = MWTidy::tidy( $text ); + // We don't care about where Tidy wants to stick is <p>s + $text = trim( preg_replace( '#</?p>#', '', $text ) ); + // Windows, we love you! + $text = str_replace( "\r", '', $text ); + $this->assertEquals( $expected, $text, $msg ); + } + + public function provideTestWrapping() { + return array( + array( + '<mw:editsection page="foo" section="bar">foo</mw:editsection>', + '<mw:editsection page="foo" section="bar">foo</mw:editsection>', + '<mw:editsection> should survive tidy' + ), + array( + '<editsection page="foo" section="bar">foo</editsection>', + '<editsection page="foo" section="bar">foo</editsection>', + '<editsection> should survive tidy' + ), + array( '<mw:toc>foo</mw:toc>', '<mw:toc>foo</mw:toc>', '<mw:toc> should survive tidy' ), + array( "<link foo=\"bar\" />\nfoo", '<link foo="bar"/>foo', '<link> should survive tidy' ), + array( "<meta foo=\"bar\" />\nfoo", '<meta foo="bar"/>foo', '<meta> should survive tidy' ), + ); + } +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/91902 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibf96cc3bc94fac75fd92ec5b9205011fcb68f0c2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: MaxSem <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
