From 5fd1e1abe0ef9e7c810a9c72fbb9104461c4e331 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Sun, 17 Dec 2017 22:12:06 +0000 Subject: [PATCH] Make Gender normalize usernames This ensures that if GENDER is fed wfEscapeWikitext()'d version of a username, it will normalize it. See discussion on T182800. Note, we do not need to worry about the case of a user named "Project:*foo" as such namespace prefixes are illegal in usernames. Change-Id: Ic5a8fc76c28dca43ce8e334ef1874c2673433f00 --- includes/parser/CoreParserFunctions.php | 4 ++-- .../parser/CoreParserFunctionsTest.php | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/includes/parser/CoreParserFunctionsTest.php diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 07944d4648..ad56afc413 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -337,8 +337,8 @@ class CoreParserFunctions { // default $gender = User::getDefaultOption( 'gender' ); - // allow prefix. - $title = Title::newFromText( $username ); + // allow prefix and normalize (e.g. "*foo" -> "*foo" ). + $title = Title::newFromText( $username, NS_USER ); if ( $title && $title->inNamespace( NS_USER ) ) { $username = $title->getText(); diff --git a/tests/phpunit/includes/parser/CoreParserFunctionsTest.php b/tests/phpunit/includes/parser/CoreParserFunctionsTest.php new file mode 100644 index 0000000000..c630447751 --- /dev/null +++ b/tests/phpunit/includes/parser/CoreParserFunctionsTest.php @@ -0,0 +1,21 @@ +setOption( 'gender', 'female' ); + $user->saveSettings(); + + $msg = ( new RawMessage( '{{GENDER:*Female|m|f|o}}' ) )->parse(); + $this->assertEquals( $msg, 'f', 'Works unescaped' ); + $escapedName = wfEscapeWikiText( '*Female' ); + $msg2 = ( new RawMessage( '{{GENDER:' . $escapedName . '|m|f|o}}' ) ) + ->parse(); + $this->assertEquals( $msg, 'f', 'Works escaped' ); + } + +} -- 2.20.1