Merge "Fix parsing usernames with +"

This commit is contained in:
jenkins-bot 2024-06-21 15:19:33 +00:00 committed by Gerrit Code Review
commit c11460a527
3 changed files with 20 additions and 2 deletions

View file

@ -1234,7 +1234,7 @@ class CommentParser {
) {
$parsoidHref = $part['template']['target']['href'];
Assert::precondition( substr( $parsoidHref, 0, 2 ) === './', "href has valid format" );
$out[] = urldecode( substr( $parsoidHref, 2 ) );
$out[] = rawurldecode( substr( $parsoidHref, 2 ) );
} else {
$out[] = null;
}

View file

@ -499,7 +499,7 @@ class CommentUtils {
) . '/';
$matches = null;
if ( preg_match( $articlePathRegexp, $path, $matches ) ) {
return urldecode( $matches[1] );
return rawurldecode( $matches[1] );
}
return null;
}

View file

@ -36,6 +36,7 @@ class CommentUtilsTest extends IntegrationTestCase {
/**
* @covers \MediaWiki\Extension\DiscussionTools\CommentUtils::getTitleFromUrl
* @dataProvider provideGetTitleFromUrl_ShortUrl
* @dataProvider provideGetTitleFromUrl_Decoding
* @dataProvider provideGetTitleFromUrl_ConfusingShortUrl
* @dataProvider provideGetTitleFromUrl_NoShortUrl
*/
@ -46,6 +47,23 @@ class CommentUtilsTest extends IntegrationTestCase {
);
}
public static function provideGetTitleFromUrl_Decoding() {
// Standard short URL configuration like on Wikimedia wikis
$config = new HashConfig( [ 'ArticlePath' => '/wiki/$1' ] );
// In URL paths, non-percent-encoded `+` represents itself
yield [ 'A+B', '/wiki/A+B', $config ];
yield [ 'A B', '/wiki/A B', $config ];
yield [ 'A+B', '/wiki/A%2BB', $config ];
yield [ 'A B', '/wiki/A%20B', $config ];
// In URL query parameters, non-percent-encoded `+` represents ` `
yield [ 'A B', '/w/index.php?title=A+B', $config ];
yield [ 'A B', '/w/index.php?title=A B', $config ];
yield [ 'A+B', '/w/index.php?title=A%2BB', $config ];
yield [ 'A B', '/w/index.php?title=A%20B', $config ];
}
public static function provideGetTitleFromUrl_ShortUrl() {
// Standard short URL configuration like on Wikimedia wikis
$config = new HashConfig( [ 'ArticlePath' => '/wiki/$1' ] );