wiki.techinc.nl/tests/phpunit/includes/GlobalFunctions/WfParseUrlTest.php
Petr Pchelko 5ad8ee4d92 Follow RFC 3986 on what is path in mailto URLs
This hack was originally added to wfParseUrl
as a fix for T10324 specifically for LinkFilter,
however according to the RFC 3986 this is wrong.

RFC defines that in URLs the authority component
must start with //, so in urls without //, e.g. news:
or mailto: there is no authority component, and thus
no host component, everything after : is actually a path,
so default PHP parse_url is correct.

RFC even has an example:
> For example, the URI <mailto:fred@example.com>
has a path of "fred@example.com".

It's fairly ugly to just copy-paste the hack
into LinkFilter, but I didn't find an easy and
elegant way to rewrite it without making any
changes to the link indexes values stored in the DB.

See https://datatracker.ietf.org/doc/html/rfc3986

Co-Authored-by: 沈澄心 <dringsim@qq.com>
Change-Id: I3dd04495db9c7a66f62c3914c0eff06754b7d560
2023-09-04 05:48:23 +00:00

53 lines
1.4 KiB
PHP

<?php
/**
* Copyright © 2013 Alexandre Emsenhuber
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
use MediaWiki\MainConfigNames;
/**
* @group GlobalFunctions
* @covers ::wfParseUrl
*/
class WfParseUrlTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
parent::setUp();
$this->overrideConfigValue( MainConfigNames::UrlProtocols, [
'//',
'http://',
'https://',
'file://',
'mailto:',
'news:',
] );
}
/**
* Same tests as the UrlUtils method
* @dataProvider UrlUtilsProviders::provideParse
*/
public function testWfParseUrl( $url, $parts ) {
$this->assertEquals(
$parts,
wfParseUrl( $url )
);
}
}