diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 07944d46489..ad56afc4130 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 00000000000..c630447751d --- /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' ); + } + +}