r95646 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95645‎ | r95646 | r95647 >
Date:04:01, 29 August 2011
Author:tstarling
Status:ok (Comments)
Tags:
Comment:
In Language::isValidBuiltInCode(), reject the empty string per Nikerabbit's request on CR r82927. I'm not sure what the reason for the request was, but I suppose an empty language code could result in the base Language class being used, which could be problematic for some caller. It doesn't do any harm to reject it here.
Modified paths:
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/Language.php
@@ -215,7 +215,7 @@
216216 * @return bool
217217 */
218218 public static function isValidBuiltInCode( $code ) {
219 - return preg_match( '/^[a-z0-9-]*$/i', $code );
 219+ return preg_match( '/^[a-z0-9-]+$/i', $code );
220220 }
221221
222222 public static function classFromCode( $code ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r98278Revert r92572: Language::isValidBuiltInCode() only rejected the empty string ...tstarling22:47, 27 September 2011

Past revisions this follows-up on

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

Comments

#Comment by Nikerabbit (talk | contribs)   05:20, 29 August 2011

The reason is my new fallback code. This function sometimes gets called with an empty string. That resulted in this exception:

mediawiki-bw_: /w/i.php?title=MediaWiki:Sitenotice&action=edit
Exception from line 909 of /www/w/includes/LocalisationCache.php: LCStore_CDB::getFileName: Invalid language ""

I began thinking why I had to write a, while I was excepting b to be enough.

a: if ( $code === '' || $code === 'en' || !Language::isValidBuiltInCode( $code ) ) {
b: if ( $code === 'en' || !Language::isValidBuiltInCode( $code ) ) {
	static function getFallbacksFor( $code ) {
		if ( $code === 'en' ) {
			return array();
		} else {
			$v = self::getLocalisationCache()->getItem( $code, 'fallback' );
			$v = array_map( 'trim', explode( ',', $v ) );
			if ( $v[count( $v ) - 1] !== 'en' ) {
				$v[] = 'en';
			}
			return $v;
		}
	}

(You can see that function is not yet fixed to validate the code.)

Status & tagging log