From: Moriel Schottlender Date: Wed, 31 Aug 2016 20:58:05 +0000 (-0700) Subject: bidi-isolate usernames in Linker::userLink X-Git-Tag: 1.31.0-rc.0~5809^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=1fff06ad2d9b75076b1aae2313cdf55c6fa2d31f;p=lhc%2Fweb%2Fwiklou.git bidi-isolate usernames in Linker::userLink Usernames can be in any script/language and include weak and neutral characters like parentheses and dashes - these flip and make things look very weird when displayed in the opposite directionality. This fix adds tags to isolate the username when we output user links. This will affect displays like user personal tools, history and diff view. Also, fixing LogFormatterTestCase::removeSomeHtml() that expected a very rigid html input (and thus failed with the new wrapping) to use strip_tags() instead. Change-Id: I2db5f4b7d3a00726461eb6b699fbdf0ecd47a1cb --- diff --git a/includes/Linker.php b/includes/Linker.php index 2b38a96591..f8b1baef13 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -993,9 +993,10 @@ class Linker { $page = Title::makeTitle( NS_USER, $userName ); } + // Wrap the output with tags for directionality isolation return self::link( $page, - htmlspecialchars( $altUserName !== false ? $altUserName : $userName ), + '' . htmlspecialchars( $altUserName !== false ? $altUserName : $userName ) . '', [ 'class' => $classes ] ); } diff --git a/tests/phpunit/includes/LinkerTest.php b/tests/phpunit/includes/LinkerTest.php index 63753f9ef3..3edf99f2e2 100644 --- a/tests/phpunit/includes/LinkerTest.php +++ b/tests/phpunit/includes/LinkerTest.php @@ -37,34 +37,34 @@ class LinkerTest extends MediaWikiLangTestCase { [ 'JohnDoe', + . 'title="Special:Contributions/JohnDoe">JohnDoe', 0, 'JohnDoe', false, ], [ '::1', + . 'title="Special:Contributions/::1">::1', 0, '::1', false, 'Anonymous with pretty IPv6' ], [ '::1', + . 'title="Special:Contributions/0:0:0:0:0:0:0:1">::1', 0, '0:0:0:0:0:0:0:1', false, 'Anonymous with almost pretty IPv6' ], [ '::1', + . 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001">::1', 0, '0000:0000:0000:0000:0000:0000:0000:0001', false, 'Anonymous with full IPv6' ], [ 'AlternativeUsername', + . 'title="Special:Contributions/::1">AlternativeUsername', 0, '::1', 'AlternativeUsername', 'Anonymous with pretty IPv6 and an alternative username' ], @@ -73,14 +73,14 @@ class LinkerTest extends MediaWikiLangTestCase { [ '127.0.0.1', + . 'title="Special:Contributions/127.0.0.1">127.0.0.1', 0, '127.0.0.1', false, 'Anonymous with IPv4' ], [ 'AlternativeUsername', + . 'title="Special:Contributions/127.0.0.1">AlternativeUsername', 0, '127.0.0.1', 'AlternativeUsername', 'Anonymous with IPv4 and an alternative username' ], diff --git a/tests/phpunit/includes/logging/LogFormatterTestCase.php b/tests/phpunit/includes/logging/LogFormatterTestCase.php index b09e5b1847..c289839b49 100644 --- a/tests/phpunit/includes/logging/LogFormatterTestCase.php +++ b/tests/phpunit/includes/logging/LogFormatterTestCase.php @@ -50,7 +50,7 @@ abstract class LogFormatterTestCase extends MediaWikiLangTestCase { private static function removeSomeHtml( $html ) { $html = str_replace( '"', '"', $html ); $html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); // Strip lrm/rlm - return trim( preg_replace( '/<(a|span)[^>]*>([^<]*)<\/\1>/', '$2', $html ) ); + return trim( strip_tags( $html ) ); } private static function removeApiMetaData( $val ) {