jenkins-bot has submitted this change and it was merged. Change subject: Gracefully handle invalid links when handling redlinks ......................................................................
Gracefully handle invalid links when handling redlinks There is no guarantee just because a link was created by parsoid that it will resolve to a valid Title object. If the link doesn't resolve to a valid title then just ignore it. Bug: 57904 Change-Id: I85ce508de311afb4ff811a1b6a8a62a7e4c5b4bf --- M includes/Templating.php 1 file changed, 10 insertions(+), 3 deletions(-) Approvals: Matthias Mullie: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Templating.php b/includes/Templating.php index 2c21acf..c36d69b 100644 --- a/includes/Templating.php +++ b/includes/Templating.php @@ -407,6 +407,11 @@ $parsoid = json_decode( $parsoid, true ); if ( isset( $parsoid['sa']['href'] ) ) { + // Don't process invalid links + $title = Title::newFromText( $parsoid['sa']['href'] ); + if ( $title === null ) { + continue; + } // gather existing link attributes $attributes = array(); foreach ( $linkNode->attributes as $attribute ) { @@ -414,7 +419,6 @@ } // let MW build link HTML based on Parsoid data - $title = Title::newFromText( $parsoid['sa']['href'] ); $linkHTML = Linker::link( $title, $linkNode->nodeValue, $attributes ); // create new DOM from this MW-built link @@ -463,7 +467,6 @@ if ( $post->isTopicTitle() ) { return array( array(), true ); } - $content = $post->getContent( 'html' ); // make sure a post is not checked more than once $revisionId = $post->getRevisionId()->getHex(); @@ -473,6 +476,7 @@ $this->parsoidLinksProcessed[$revisionId] = true; // find links in DOM + $content = $post->getContent( 'html' ); $dom = ParsoidUtils::createDOM( $content ); $xpath = new \DOMXPath( $dom ); $linkNodes = $xpath->query( '//a[@rel="mw:WikiLink"][@data-parsoid]' ); @@ -484,7 +488,10 @@ if ( isset( $parsoid['sa']['href'] ) ) { // real results will be stored in Templating::parsoidLinks $link = $parsoid['sa']['href']; - $this->parsoidLinks[$link] = Title::newFromText( $link ); + $title = Title::newFromText( $link ); + if ( $title !== null ) { + $this->parsoidLinks[$link] = $title; + } } } -- To view, visit https://gerrit.wikimedia.org/r/98744 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I85ce508de311afb4ff811a1b6a8a62a7e4c5b4bf Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits