r83160 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83159‎ | r83160 | r83161 >
Date:19:13, 3 March 2011
Author:hashar
Status:resolved (Comments)
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/languages/LanguageTest.php
@@ -58,4 +58,27 @@
5959 'formatTimePeriod() rounding (>=1h)'
6060 );
6161 }
 62+
 63+ /**
 64+ * Test Language::isValidBuiltInCode()
 65+ * @dataProvider provideLanguageCodes
 66+ */
 67+ function testBuiltInCodeValidation( $code, $message = '' ) {
 68+ $this->assertTrue(
 69+ (bool) Language::isValidBuiltInCode( $code ),
 70+ "validating code $code $message"
 71+ );
 72+ }
 73+
 74+ function provideLanguageCodes() {
 75+ return array(
 76+ array( 'fr' , 'Two letters, minor case' ),
 77+ array( 'EN' , 'Two letters, upper case' ),
 78+ array( 'tyv' , 'Three letters' ),
 79+ array( 'tokipona' , 'long language code' ),
 80+ array( 'be_tarask', 'With underscore' ),
 81+ array( 'Zh_classical', 'Begin with upper case, underscore' ),
 82+ array( 'Be_x_old', 'With extension (two underscores)' ),
 83+ );
 84+ }
6285 }
Index: trunk/phase3/languages/Language.php
@@ -215,7 +215,7 @@
216216 * internal customisation of MediaWiki, via Messages*.php.
217217 */
218218 public static function isValidBuiltInCode( $code ) {
219 - return preg_match( '/^[a-z0-9-]*$/', $code );
 219+ return preg_match( '/^[a-z0-9-_]*$/i', $code );
220220 }
221221
222222 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r83223Underscore are not valid in language code...hashar17:16, 4 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82927Followup for r81340:...tstarling03:15, 28 February 2011

Comments

#Comment by Siebrand (talk | contribs)   20:26, 3 March 2011

The language code does not contain an underscore (it is "be-tarask"). The core messages file contains an underscore ("MessagesBe_tarask.php). If this was the reason for your change, it was unneeded and should probably be reverted. Same goes for be-x-old and zh-classical, btw.

#Comment by Hashar (talk | contribs)   17:16, 4 March 2011

Tests and factory made to use dashes in r83223

Status & tagging log