Correct the regular expression for explicit plural forms
authorSanthosh Thottingal <santhosh.thottingal@gmail.com>
Tue, 23 Jul 2013 15:03:04 +0000 (20:33 +0530)
committerSanthosh Thottingal <santhosh.thottingal@gmail.com>
Tue, 23 Jul 2013 15:08:52 +0000 (20:38 +0530)
/\d+=/ will match a12=abc. That is wrong. The plural form must
start with digits. Changing it to /^\d+=/

Also avoid Regex instance creation in mediawiki.language.js, use
literal regex.

Follow up: I82b9067 and I50eb0c6
Bug: 51284

Change-Id: I70ad3f99ad0a2600773c005d9e9cc8238e6e6d09

languages/Language.php
resources/mediawiki.language/mediawiki.language.js

index e5cab05..262d86f 100644 (file)
@@ -3616,7 +3616,7 @@ class Language {
        function convertPlural( $count, $forms ) {
                // Handle explicit n=pluralform cases
                foreach ( $forms as $index => $form ) {
-                       if ( preg_match( '/\d+=/i', $form ) ) {
+                       if ( preg_match( '/^\d+=/i', $form ) ) {
                                $pos = strpos( $form, '=' );
                                if ( substr( $form, 0, $pos ) === (string) $count ) {
                                        return substr( $form, $pos + 1 );
index 8cf358b..631d13d 100644 (file)
@@ -46,7 +46,6 @@ var language = {
        convertPlural: function ( count, forms ) {
                var pluralRules,
                        formCount,
-                       explicitPluralPattern = new RegExp( '\\d+=', 'i' ),
                        form,
                        index,
                        equalsPosition,
@@ -59,7 +58,7 @@ var language = {
                // Handle for explicit n= forms
                for ( index = 0; index < forms.length; index++ ) {
                        form = forms[index];
-                       if ( explicitPluralPattern.test( form ) ) {
+                       if ( /^\d+=/.test( form ) ) {
                                equalsPosition = form.indexOf( '=' );
                                formCount = parseInt( form.substring( 0, equalsPosition ), 10 );
                                if ( formCount === count ) {