Skip to content

Commit

Permalink
LinkFilter::makeLikeArray: Fix another 'path' access
Browse files Browse the repository at this point in the history
If a news: or mailto: URL is specified with two slashes, it will have a
'host' rather than a 'path' after all, so this workaround is unnecessary
and should be skipped in that case; compare also change Idc6b389da9
(commit ec1b572) for makeIndexes().

I鈥檓 not very sure that the test case makes much sense, but it鈥檚 at least
enough to trigger the error and verify the fix.

Bug: T364743
Change-Id: I09be813e661b80968da00d8a898b2add8c95fec7
  • Loading branch information
lucaswerkmeister committed May 14, 2024
1 parent 2f4ed86 commit 8908074
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion includes/ExternalLinks/LinkFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ public static function makeLikeArray( $filterEntry, $protocol = 'http:https://' ) {
// while we want to match the email's domain or news server the same way we are
// matching hosts for other URLs.
if ( in_array( $bits['scheme'], [ 'mailto', 'news' ] ) ) {
$bits['host'] = $bits['path'];
// (T364743) Only set host if it's not already set (if // is used)
if ( array_key_exists( 'path', $bits ) ) {
$bits['host'] = $bits['path'];
}
$bits['path'] = '';
}

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/includes/ExternalLinks/LinkFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public static function provideValidPatterns() {
// (T347574) Only set host if it's not already set (if // is used)
[ 'news:', 'comp.compression', 'news:https://comp.compression' ],
[ 'news:', 'comp.compression', 'news:comp.compression' ],
// (T364743) Also only set host if it's not already set, but in a different code path
[ '', 'news:https://*.example.com', 'news:https://example.org', [ 'found' => false ] ],

[ '', 'git:https://github.com/prwef/abc-def.git', 'git:https://github.com/prwef/abc-def.git' ],
[ 'git:https://', 'github.com/', 'git:https://github.com/prwef/abc-def.git' ],
Expand Down

0 comments on commit 8908074

Please sign in to comment.