From: Chad Horohoe Date: Wed, 16 Jul 2014 18:13:56 +0000 (-0700) Subject: Language::isValidBuiltInCode() should not accept uppercase input X-Git-Tag: 1.31.0-rc.0~14883^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dcompta/operations/supprimer.php?a=commitdiff_plain;h=fca0d37a2c9822f7edaaae86570b2811b7026377;p=lhc%2Fweb%2Fwiklou.git Language::isValidBuiltInCode() should not accept uppercase input The results of this function are used to decide whether a code is valid for loading an i18n file without any further normalization. Partially reverts 93348f3 which made the regular expression case- insensitive. Per IRC discussion, language codes should always be lowercase and it's up to callers to deal with that. Change-Id: I8975c3374a37935080d9f7eca6a602e32f67a87b --- diff --git a/languages/Language.php b/languages/Language.php index 0a19d61111..887490bcea 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -339,7 +339,7 @@ class Language { throw new MWException( __METHOD__ . " must be passed a string, $type given$addmsg" ); } - return (bool)preg_match( '/^[a-z0-9-]{2,}$/i', $code ); + return (bool)preg_match( '/^[a-z0-9-]{2,}$/', $code ); } /** diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index ef670df53e..ec514413c2 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -457,32 +457,22 @@ class LanguageTest extends LanguageClassesTestCase { * @dataProvider provideLanguageCodes * @covers Language::isValidBuiltInCode */ - public function testBuiltInCodeValidation( $code, $message = '' ) { - $this->assertTrue( + public function testBuiltInCodeValidation( $code, $expected, $message = '' ) { + $this->assertEquals( $expected, (bool)Language::isValidBuiltInCode( $code ), "validating code $code $message" ); } - /** - * @covers Language::isValidBuiltInCode - */ - public function testBuiltInCodeValidationRejectUnderscore() { - $this->assertFalse( - (bool)Language::isValidBuiltInCode( 'be_tarask' ), - "reject underscore in language code" - ); - } - public static function provideLanguageCodes() { return array( - array( 'fr', 'Two letters, minor case' ), - array( 'EN', 'Two letters, upper case' ), - array( 'tyv', 'Three letters' ), - array( 'tokipona', 'long language code' ), - array( 'be-tarask', 'With dash' ), - array( 'Zh-classical', 'Begin with upper case, dash' ), - array( 'Be-x-old', 'With extension (two dashes)' ), + array( 'fr', true, 'Two letters, minor case' ), + array( 'EN', false, 'Two letters, upper case' ), + array( 'tyv', true, 'Three letters' ), + array( 'tokipona', true, 'long language code' ), + array( 'be-tarask', true, 'With dash' ), + array( 'be-x-old', true, 'With extension (two dashes)' ), + array( 'be_tarask', false, 'Reject underscores' ), ); }