From fca0d37a2c9822f7edaaae86570b2811b7026377 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 16 Jul 2014 11:13:56 -0700 Subject: [PATCH] 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 --- languages/Language.php | 2 +- tests/phpunit/languages/LanguageTest.php | 28 ++++++++---------------- 2 files changed, 10 insertions(+), 20 deletions(-) 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' ), ); } -- 2.20.1