Language::convertPlural: check if matching form exists
authorKevin Israel <pleasestand@live.com>
Sat, 25 May 2013 23:19:55 +0000 (19:19 -0400)
committerKevin Israel <pleasestand@live.com>
Sat, 25 May 2013 23:30:53 +0000 (19:30 -0400)
It is possible that only explicit plural forms are specified, and
therefore, it is possible that none match. However, handling of
explicit forms came after the count( $forms ) check, so input such
as {{PLURAL:|1=}} would trigger a "PHP Notice: Undefined offset: -1".

Change-Id: I8494de8ceb9e0cfff7203c69c21f02b3731275af
Follows-Up: I50eb0c6d1c02ca936848d310de625ed1fe43d91a

RELEASE-NOTES-1.22
languages/Language.php
tests/phpunit/languages/LanguageTest.php

index 361ab25..b6a8e29 100644 (file)
@@ -106,6 +106,7 @@ production.
   strings will now start with digits 0 and 8-f as often as they should.
 * (bug 45371) Removed Parser_LinkHooks and CoreLinkFunctions classes.
 * (bug 41545) Allow <kbd>, <samp>, and <var> to be nested like allowed in html.
+* PLURAL magic word no longer causes a PHP notice when no matching form exists.
 
 === API changes in 1.22 ===
 * (bug 46626) xmldoublequote parameter was removed. Because of a bug, the
index c73ccd1..9301e54 100644 (file)
@@ -3597,10 +3597,6 @@ class Language {
         * @return string Correct form of plural for $count in this language
         */
        function convertPlural( $count, $forms ) {
-               if ( !count( $forms ) ) {
-                       return '';
-               }
-
                // Handle explicit n=pluralform cases
                foreach ( $forms as $index => $form ) {
                        if ( preg_match( '/\d+=/i', $form ) ) {
@@ -3611,7 +3607,11 @@ class Language {
                                unset( $forms[$index] );
                        }
                }
+
                $forms = array_values( $forms );
+               if ( !count( $forms ) ) {
+                       return '';
+               }
 
                $pluralForm = $this->getPluralRuleIndexNumber( $count );
                $pluralForm = min( $pluralForm, count( $forms ) - 1 );
index 54f7753..d687dbb 100644 (file)
@@ -1384,6 +1384,9 @@ class LanguageTest extends LanguageClassesTestCase {
                        array( 'other', 2, array(
                                'kissa=kala', '1=2=3', 'other',
                        ) ),
+                       array( '', 2, array(
+                               '0=explicit zero', '1=explicit one',
+                       ) ),
                );
        }