ZF-9293: Wrong behavior in Zend_Validate_Int and Zend_Validate_Float when locale is present.
Description
When locale is present, isValid() shouldn't test using 'en' locale also. A example of this inconsistency is:
//consider Zend_Locale is already in Zend_Registry and it's 'pt_BR'
$number = $_POST['VALUE_IN_BRL'] // Value must be in Brazil's currency format, but let's suppose user typed 2,500.99 ('en' format)
$validate = new Zend_Validate_Float();
if(is_valid($number)){
//get number from localized string and save it to database
$number = Zend_Locale_Format::getNumber($number);
}
else{
$msg = 'Enter the correct value!'
}
In addition to wrong behavior (2,500.99 is not valid in my application), i get this error:
Uncaught exception 'Zend_Locale_Exception' with message 'No localized value in 2,500.99 found, or the given number does not match the localized format' in path_to_zf\library\Zend\Locale\Format.php:247
Comments
Posted by Benjamin-Timm Broich (chameleon) on 2010-03-05T02:03:01.000+0000
One of my co-workers noticed me about the above mentioned code thats not working. Its still checking against the "en" locale, instaed of checking against the given de_DE locale.
I think that it's not necessary to check against the english locale if another locale (in this case de_DE) is given?!
Posted by Benjamin-Timm Broich (chameleon) on 2010-03-05T02:08:19.000+0000
Additionally to my comment above:
As we can see, the Float Validator always checks for the english locale.
Posted by Leandro Rodrigues Chaves (leandrorc) on 2010-03-05T03:29:51.000+0000
Exactly Benjamin! Same with Zend_Validate_Int. Another example why isValid() shouldn't test against 'en' could be in a financial test, when students must type the number format of many countries and the application must validate this.
Posted by Thomas Weidner (thomas) on 2010-03-05T14:53:11.000+0000
Reducing from critical to major. The inclusion of EN was forced by the core team despite my negative response to this request. Has to be discussed with team members before changing this in my eyes errorous behaviour.
Posted by Thomas Weidner (thomas) on 2010-03-27T14:31:45.000+0000
Not reproducable for Zend_Validate_Int. There is no relation to "en" within the Int validator.
Posted by Thomas Weidner (thomas) on 2010-04-26T11:44:44.000+0000
Closing as not reproduceable
Wether Int nor Float have a fixed "en" locale as mentioned. Both validators do not validate localized "en" numbers when another locale is given within or after the mentioned release