Avoid exceptions by first checking language code validity
authorNiklas Laxström <niklas.laxstrom@gmail.com>
Tue, 11 Jun 2013 16:42:10 +0000 (16:42 +0000)
committerNiklas Laxström <niklas.laxstrom@gmail.com>
Thu, 13 Jun 2013 09:35:32 +0000 (09:35 +0000)
Bug: 49423
Change-Id: I3fd98ba08393856311a48fa40769027460c72ef9

languages/Language.php
tests/phpunit/languages/LanguageTest.php

index 92ea75c..00f654b 100644 (file)
@@ -385,6 +385,12 @@ class Language {
        public static function isKnownLanguageTag( $tag ) {
                static $coreLanguageNames;
 
+               // Quick escape for invalid input to avoid exceptions down the line
+               // when code tries to process tags which are not valid at all.
+               if ( !self::isValidBuiltInCode( $tag ) ) {
+                       return false;
+               }
+
                if ( $coreLanguageNames === null ) {
                        include MWInit::compiledPath( 'languages/Names.php' );
                }
index d687dbb..42be936 100644 (file)
@@ -494,6 +494,7 @@ class LanguageTest extends LanguageClassesTestCase {
        public static function provideUnknownLanguageTags() {
                return array(
                        array( 'mw', 'non-existent two-letter code' ),
+                       array( 'foo"<bar', 'very invalid language code' ),
                );
        }