From 4b1db1190bb8f2a115c6a81a5ee487b7d18cd303 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Thu, 27 Sep 2018 17:45:04 -0400 Subject: [PATCH] Tidy Message::parseAsBlock() by enabling tidy in MessageCache We are incrementally removing places where the parser is used with tidy disabled, since future parsers will not support such operation. Bug: T198214 Change-Id: I0f417f75a49dfea873e9a2f44d81796a48b9f428 --- includes/cache/MessageCache.php | 3 +++ tests/phpunit/includes/OutputPageTest.php | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index 869f768c44..5dee0f696c 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -198,6 +198,7 @@ class MessageCache { // either. $po = ParserOptions::newFromAnon(); $po->setAllowUnsafeRawHtml( false ); + $po->setTidy( true ); return $po; } @@ -206,6 +207,8 @@ class MessageCache { // from malicious sources. As a precaution, disable // the parser tag when parsing messages. $this->mParserOptions->setAllowUnsafeRawHtml( false ); + // For the same reason, tidy the output! + $this->mParserOptions->setTidy( true ); } return $this->mParserOptions; diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 53e6f464c9..b19cd2b251 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -1634,9 +1634,8 @@ class OutputPageTest extends MediaWikiTestCase { $op = $this->newInstance(); $this->assertSame( '', $op->getHTML() ); $op->addWikiMsg( 'parentheses', "a" ); - // This is known to be bad unbalanced HTML; this will be fixed - // by I743f4185a03403f8d9b9db010ff1ee4e9342e062 (T198214) - $this->assertSame( "

(a)\n

", $op->getHTML() ); + // The input is bad unbalanced HTML, but the output is tidied + $this->assertSame( "

(a)\n

", $op->getHTML() ); } /** -- 2.20.1