ZF-11631: Zend_Filter_Alnum and Alpha not referring locale through Zend_Registry

Description

h1. ISSUE forcing app's locale to 'ja'


$locale = Zend_Locale('ja');
Zend_Registry::set('Zend_Locale', $locale);

but Zend_Filter_Alnum (and Alpha) is ignoring it:


# Zend/Filter/Alnum.php line 92
# and Zend/Filter/Alpha.php line 92
...
this->_locale = new Zend_Locale('auto');
...

so alphabet+num validation is broken with multi-byte texts:


$va = new Zend_Validate_Alnum();
$va->isValid( $some_mb_str );
# -> true (but should be false, since it's not [a-zA-Z])

h1. THE FIX * it should refer to Zend_Registry first. * like Zend/Validate/Date.php line 97

here is the path for Alpha.php (should be the same for Alnum.php too)


diff -Naru Alpha.php.original Alpha.php 
--- Alpha.php.original  2011-07-31 01:59:34.000000000 +0900
+++ Alpha.php   2011-07-31 01:59:40.000000000 +0900
@@ -89,7 +89,11 @@
         }
 
         if (null === self::$_meansEnglishAlphabet) {
-            $this->_locale = new Zend_Locale('auto');
+            require_once 'Zend/Registry.php';
+            if (Zend_Registry::isRegistered('Zend_Locale'))
+                $this->_locale = Zend_Registry::get('Zend_Locale');
+            else
+                $this->_locale = new Zend_Locale('auto');
             self::$_meansEnglishAlphabet = in_array($this->_locale->getLanguage(),
                                                     array('ja', 'ko', 'zh')
                                                     );

Comments

Changing from bug to improvement. Note that most filters are for now not locale-aware.

Fixed in ZF2 with GH-416