From e376d6ed54c1e1b9bba001a3043b57e13fa40f1d Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Thu, 9 May 2024 14:16:42 +0200 Subject: [PATCH] Skin: Fix UrlUtils calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was broken in change I9a55545e4c (commit b90e0e4261): wfUrlProtocols() without argument is equivalent to validProtocols(), not validAbsoluteProtocols() (wfUrlProtocols()’s $includeProtocolRelative defaults to true). Bug: T364539 Change-Id: I050ed65624928ee8277468f70b8b80a3080f190a --- includes/skins/Skin.php | 4 +-- tests/phpunit/includes/skins/SideBarTest.php | 28 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index 2eac6c36987..ed8a2190638 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -1140,7 +1140,7 @@ abstract class Skin extends ContextSource { * @return string URL */ public static function makeInternalOrExternalUrl( $name ) { - $protocols = MediaWikiServices::getInstance()->getUrlUtils()->validAbsoluteProtocols(); + $protocols = MediaWikiServices::getInstance()->getUrlUtils()->validProtocols(); if ( preg_match( '/^(?i:' . $protocols . ')/', $name ) ) { return $name; @@ -1617,7 +1617,7 @@ abstract class Skin extends ContextSource { $text = $line[1]; } - if ( preg_match( '/^(?i:' . $urlUtils->validAbsoluteProtocols() . ')/', $link ) ) { + if ( preg_match( '/^(?i:' . $urlUtils->validProtocols() . ')/', $link ) ) { $href = $link; // Parser::getExternalLinkAttribs won't work here because of the Namespace things diff --git a/tests/phpunit/includes/skins/SideBarTest.php b/tests/phpunit/includes/skins/SideBarTest.php index e92997588f7..de927fb343d 100644 --- a/tests/phpunit/includes/skins/SideBarTest.php +++ b/tests/phpunit/includes/skins/SideBarTest.php @@ -150,6 +150,34 @@ class SideBarTest extends MediaWikiLangTestCase { ); } + public function testProtocolRelativeExternalUrl() { + $this->overrideConfigValues( [ + MainConfigNames::NoFollowLinks => true, + MainConfigNames::NoFollowDomainExceptions => [], + MainConfigNames::NoFollowNsExceptions => [], + ] ); + + $bar = []; + $text = '* Title +** //www.mediawiki.org/| Home +'; + $this->skin->addToSidebarPlain( $bar, $text ); + $this->assertEquals( + [ 'Title' => [ + # ** //www.mediawiki.org/| Home + [ + 'text' => 'Home', + 'href' => '//www.mediawiki.org/', // not /wiki///www.mediawiki.org/ (T364539) + 'id' => 'n-Home', + 'active' => null, + 'icon' => null, + 'rel' => 'nofollow', + ], + ] ], + $bar + ); + } + private function getAttribs() { # Sidebar text we will use everytime $text = '* Title