http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90709

Revision: 90709
Author:   salvatoreingala
Date:     2011-06-24 10:38:51 +0000 (Fri, 24 Jun 2011)
Log Message:
-----------
Limiting gadget's preference names to 40 characters.

Modified Paths:
--------------
    branches/salvatoreingala/Gadgets/Gadgets_tests.php
    branches/salvatoreingala/Gadgets/backend/Gadget.php

Modified: branches/salvatoreingala/Gadgets/Gadgets_tests.php
===================================================================
--- branches/salvatoreingala/Gadgets/Gadgets_tests.php  2011-06-24 10:22:21 UTC 
(rev 90708)
+++ branches/salvatoreingala/Gadgets/Gadgets_tests.php  2011-06-24 10:38:51 UTC 
(rev 90709)
@@ -108,6 +108,29 @@
                        )
                ) ) );
 
+               //Test with too long preference name (41 characters)
+               $this->assertFalse( Gadget::isPrefsDescriptionValid( array(
+                       'fields' => array(
+                               'aPreferenceNameExceedingTheLimitOf40Chars' => 
array(
+                                       'type' => 'boolean',
+                                       'label' => 'foo',
+                                       'default' => true
+                               )
+                       )
+               ) ) );
+
+               //This must pass, instead (40 characters is fine)
+               $this->assertTrue( Gadget::isPrefsDescriptionValid( array(
+                       'fields' => array(
+                               'otherPreferenceNameThatS40CharactersLong' => 
array(
+                                       'type' => 'boolean',
+                                       'label' => 'foo',
+                                       'default' => true
+                               )
+                       )
+               ) ) );
+
+
                //Test with an unexisting field parameter
                $this->assertFalse( Gadget::isPrefsDescriptionValid( array(
                        'fields' => array(

Modified: branches/salvatoreingala/Gadgets/backend/Gadget.php
===================================================================
--- branches/salvatoreingala/Gadgets/backend/Gadget.php 2011-06-24 10:22:21 UTC 
(rev 90708)
+++ branches/salvatoreingala/Gadgets/backend/Gadget.php 2011-06-24 10:38:51 UTC 
(rev 90709)
@@ -581,7 +581,9 @@
                        }
                        
                        //check $option name compliance
-                       if ( !preg_match( '/^[a-zA-Z_][a-zA-Z0-9_]*$/', $option 
) ) {
+                       if ( strlen( $option ) > 40 
+                               || !preg_match( '/^[a-zA-Z_][a-zA-Z0-9_]*$/', 
$option ) )
+                       {
                                return false;
                        }
                        


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to