jenkins-bot has submitted this change and it was merged. Change subject: Gracefully handle errors applying redlinks ......................................................................
Gracefully handle errors applying redlinks An invalid wikilink like [[Foo&bar]], when it gets through to the redlink handling, will error out because &bar is not a valid html entity. This first repair sets up more gracefull error handling for failures in redlinking(just show the content without redlinks applied). A future fix will also address the html entity in url problem. Bug: 58455 Change-Id: Iaa36485325668af4bb7b4556e6dedf9c9d3bf346 --- M includes/ParsoidUtils.php M includes/Templating.php M tests/TemplatingTest.php 3 files changed, 26 insertions(+), 8 deletions(-) Approvals: Spage: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/ParsoidUtils.php b/includes/ParsoidUtils.php index 0a638ab..a259c81 100644 --- a/includes/ParsoidUtils.php +++ b/includes/ParsoidUtils.php @@ -197,15 +197,16 @@ return !in_array( $error->code, $ignoreErrorCodes ); } ); + + // restore libxml state before anything else + libxml_clear_errors(); + libxml_use_internal_errors( $useErrors ); + if ( $errors ) { throw new \MWException( implode( "\n", array_map( function( $error ) { return $error->message; }, $errors ) ) ); } - - // restore libxml error reporting - libxml_clear_errors(); - libxml_use_internal_errors( $useErrors ); return $dom; } diff --git a/includes/Templating.php b/includes/Templating.php index 0924bb7..1e57d61 100644 --- a/includes/Templating.php +++ b/includes/Templating.php @@ -276,7 +276,7 @@ * RecentChanges pages. * * Moderation-aware. - * + * * @param AbstractRevision $revision Revision to display * @param User $permissionsUser The User to check permissions for * @return string HTML @@ -359,7 +359,13 @@ if ( $format === 'html' ) { // Parsoid doesn't render redlinks - $content = $this->applyRedlinks( $content ); + try { + $content = $this->applyRedlinks( $content ); + } catch ( \Exception $e ) { + wfDebugLog( __CLASS__, __METHOD__ . ': Failed applying redlinks for rev_id = ' . $revision->getRevisionId()->getHex() ); + \MWExceptionHandler::logException( $e ); + } + } return $content; @@ -433,7 +439,7 @@ } // let MW build link HTML based on Parsoid data - $linkHTML = Linker::link( $title, $linkNode->nodeValue, $attributes ); + $linkHTML = Linker::link( $title, htmlspecialchars( $linkNode->nodeValue ), $attributes ); // create new DOM from this MW-built link $linkDom = ParsoidUtils::createDOM( $linkHTML ); diff --git a/tests/TemplatingTest.php b/tests/TemplatingTest.php index edc213e..9efd856 100644 --- a/tests/TemplatingTest.php +++ b/tests/TemplatingTest.php @@ -45,6 +45,14 @@ // expect string htmlentities( 'Main_Page/SubPage&action=edit&redlink=1' ), ), + + array( + 'Link containing html entities should be properly handled', + // title text from parsoid + 'Foo&bar', + // expect string + htmlspecialchars( 'Foo%26bar&action=edit&redlink=1' ), + ), ); } @@ -56,8 +64,11 @@ $this->setMwGlobals( 'wgTitle', Title::newMainPage() ); $parsoid = htmlentities( json_encode( array( 'sa' => array( 'href' => $saHref ) ) ) ); + $uid = Model\UUID::create( '0509b4bf4b2d616abe79080027a08222' ); $rev = Model\PostRevision::fromStorageRow( array( - 'rev_content' => '<a rel="mw:WikiLink" data-parsoid="' . $parsoid . '"></a>', + 'rev_id' => $uid->getBinary(), + 'tree_rev_id' => $uid->getBinary(), + 'rev_content' => '<a rel="mw:WikiLink" data-parsoid="' . $parsoid . '">' . htmlspecialchars( $saHref ) . '</a>', 'rev_flags' => 'html' ) + self::$postRow ); -- To view, visit https://gerrit.wikimedia.org/r/101236 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iaa36485325668af4bb7b4556e6dedf9c9d3bf346 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Spage <sp...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits