Fix language code validation (from r82927)
A language code may contains the underscore character (be_tarask) and might as well be upper case (FR). Add tests for Language::isValidBuiltInCode() against some language codes
This commit is contained in:
parent
8b9af2f364
commit
93348f39d4
2 changed files with 24 additions and 1 deletions
|
|
@ -215,7 +215,7 @@ class Language {
|
||||||
* internal customisation of MediaWiki, via Messages*.php.
|
* internal customisation of MediaWiki, via Messages*.php.
|
||||||
*/
|
*/
|
||||||
public static function isValidBuiltInCode( $code ) {
|
public static function isValidBuiltInCode( $code ) {
|
||||||
return preg_match( '/^[a-z0-9-]*$/', $code );
|
return preg_match( '/^[a-z0-9-_]*$/i', $code );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -58,4 +58,27 @@ class LanguageTest extends MediaWikiTestCase {
|
||||||
'formatTimePeriod() rounding (>=1h)'
|
'formatTimePeriod() rounding (>=1h)'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Language::isValidBuiltInCode()
|
||||||
|
* @dataProvider provideLanguageCodes
|
||||||
|
*/
|
||||||
|
function testBuiltInCodeValidation( $code, $message = '' ) {
|
||||||
|
$this->assertTrue(
|
||||||
|
(bool) Language::isValidBuiltInCode( $code ),
|
||||||
|
"validating code $code $message"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 underscore' ),
|
||||||
|
array( 'Zh_classical', 'Begin with upper case, underscore' ),
|
||||||
|
array( 'Be_x_old', 'With extension (two underscores)' ),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue