ExternalLinks: fix mailto: links reversal

If $mailparts does not contain two elements (which would be the case when the separator `@` is not present in the string), then we cannot
access $mailparts[1].

In this case, the entire path as is, is treated as the host.

Bug: T380880
Change-Id: I10187c93e67ce9294ff0b3866939d2c7d7292a9a
(cherry picked from commit c2db58c55bef207dd37ac5fe0b07aa28ee4bd2d5)
This commit is contained in:
Ammarpad 2024-11-26 16:57:59 +01:00
parent 05cce96a77
commit c373e0ba40
2 changed files with 7 additions and 2 deletions

View file

@ -271,11 +271,11 @@ class LinkFilter {
$mailparts = explode( '@', $bits['path'], 2 );
if ( count( $mailparts ) === 2 ) {
$domainpart = rtrim( self::reverseDomain( $mailparts[0] ), '.' );
$bits['host'] = $mailparts[1] . '@' . $domainpart;
} else {
// No @, assume it's a local part with no domain
$domainpart = '';
$bits['host'] = $mailparts[0];
}
$bits['host'] = $mailparts[1] . '@' . $domainpart;
} else {
$bits['host'] = rtrim( self::reverseDomain( $bits['host'] ), '.' );
}

View file

@ -415,6 +415,11 @@ class LinkFilterTest extends MediaWikiLangTestCase {
'mailto:@wiki',
'mailto:wiki@'
],
[
// mailtos are handled special
'mailto:wiki',
'mailto:wiki'
],
// file URL cases per T30627...
[