jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/374702 )
Change subject: Replace spaces with %20 and trim user input ...................................................................... Replace spaces with %20 and trim user input * Make sure there are no leading or trailing spaces by using trim() * Replacing spaces with %20 is always safe, so normalize to that form Change-Id: Ic0fd36878e2e8c4f8b32c3b47b278d081b919713 --- M UrlShortenerUtils.php M tests/phpunit/UrlShortenerUtilsTest.php 2 files changed, 6 insertions(+), 2 deletions(-) Approvals: jenkins-bot: Verified Jforrester: Looks good to me, approved diff --git a/UrlShortenerUtils.php b/UrlShortenerUtils.php index 8b81939..6c0073e 100644 --- a/UrlShortenerUtils.php +++ b/UrlShortenerUtils.php @@ -94,9 +94,13 @@ // it to a different one when redirecting $url = self::convertToProtocol( $url, PROTO_HTTP ); + $url = trim( $url ); + // TODO: We should ideally decode/encode the URL for normalization, // but we don't want to double-encode, nor unencode the URL that // is directly provided by users (see test cases) + // So for now, just replace spaces with %20, as that's safe in all cases + $url = str_replace( ' ', '%20', $url ); // If the wiki is using an article path (e.g. /wiki/$1) try // and convert plain index.php?title=$1 URLs to the canonical form diff --git a/tests/phpunit/UrlShortenerUtilsTest.php b/tests/phpunit/UrlShortenerUtilsTest.php index 08afb75..2ea1f34 100644 --- a/tests/phpunit/UrlShortenerUtilsTest.php +++ b/tests/phpunit/UrlShortenerUtilsTest.php @@ -105,10 +105,10 @@ 'http://example.org/wiki/Scott_Morrison_(politician)', 'http://example.org/wiki/Scott_Morrison_(politician)' ], - // Ideally spaces should be replaced with underscores + // Ideally spaces should be replaced with underscores for MediaWiki links [ 'http://example.org/wiki/Scott Morrison (politician)', - 'http://example.org/wiki/Scott Morrison (politician)' + 'http://example.org/wiki/Scott%20Morrison%20(politician)' ], // encoded # in URL that is not an anchor [ -- To view, visit https://gerrit.wikimedia.org/r/374702 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic0fd36878e2e8c4f8b32c3b47b278d081b919713 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/UrlShortener Gerrit-Branch: master Gerrit-Owner: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Thiemo Kreuz (WMDE) <thiemo.kr...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits