mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-30 11:07:24 +00:00
Fix parsing usernames with +
urldecode() should be used for decoding URL query parameters, rawurldecode() should be used for decoding URL paths. Bug: T367977 Change-Id: I7a7b14da85fb89f612c701d2746803d830017842
This commit is contained in:
parent
aff2c0be56
commit
20ff1a519f
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -499,7 +499,7 @@ class CommentUtils {
|
|||
) . '/';
|
||||
$matches = null;
|
||||
if ( preg_match( $articlePathRegexp, $path, $matches ) ) {
|
||||
return urldecode( $matches[1] );
|
||||
return rawurldecode( $matches[1] );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -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' ] );
|
||||
|
|
Loading…
Reference in a new issue