From c99e3d537ede1628f1bc2d833e5285a2dd083399 Mon Sep 17 00:00:00 2001 From: "This, that and the other" Date: Fri, 29 Jan 2016 01:03:18 +1100 Subject: [PATCH] Linker: Avoid passing false to Title::newFromText This is needed because the call to substr() returns false when the string is only 1 character long, which occurs when parsing degenerate links like [[:]] and [[::|foo]]. The seemingly unnecessary test for $match[1] !== '' is for forwards compatibility with PHP 7. Bug: T121706 Change-Id: Icc19ee990d01958d64b938d298e9a7e1df7181b5 --- includes/Linker.php | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 8e79d9c38e..43df8397cf 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1449,31 +1449,34 @@ class Linker { } } else { # Other kind of link - if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) { - $trail = $submatch[1]; - } else { - $trail = ""; - } - $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; + # Make sure its target is non-empty if ( isset( $match[1][0] ) && $match[1][0] == ':' ) { $match[1] = substr( $match[1], 1 ); } - list( $inside, $trail ) = Linker::splitTrail( $trail ); - - $linkText = $text; - $linkTarget = Linker::normalizeSubpageLink( $title, $match[1], $linkText ); - - $target = Title::newFromText( $linkTarget ); - if ( $target ) { - if ( $target->getText() == '' && !$target->isExternal() - && !$local && $title - ) { - $newTarget = clone $title; - $newTarget->setFragment( '#' . $target->getFragment() ); - $target = $newTarget; + if ( $match[1] !== false && $match[1] !== '' ) { + if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) { + $trail = $submatch[1]; + } else { + $trail = ""; } + $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/'; + list( $inside, $trail ) = Linker::splitTrail( $trail ); + + $linkText = $text; + $linkTarget = Linker::normalizeSubpageLink( $title, $match[1], $linkText ); + + $target = Title::newFromText( $linkTarget ); + if ( $target ) { + if ( $target->getText() == '' && !$target->isExternal() + && !$local && $title + ) { + $newTarget = clone $title; + $newTarget->setFragment( '#' . $target->getFragment() ); + $target = $newTarget; + } - $thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail; + $thelink = Linker::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail; + } } } if ( $thelink ) { -- 2.20.1