Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.5.2
-
Fix Version/s: 1.8.0
-
Component/s: Zend_Validate
-
Labels:None
Description
The php function strval use the decimal point character that is defined in the script's locale (category LC_NUMERIC), so depending on the local set in PHP.
For instance, strval(1.2) return "1,2" in "fr_FR.utf8" locale.
So basicaly the isValid() function of the Zend_Validate_Float class does this :
$locale = localeconv();
$valueFiltered = str_replace($locale['thousands_sep'], '', $valueString);
$valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered);
if (strval(floatval($valueFiltered)) != $valueFiltered) {
/* only true if the $locale['thousands_sep'] is already '' and $locale['decimal_point'] is already '.' */
Here, the code replace the locale decimal point by '.' and remove the locale thousand separator and then compare this string to the same string, convertred to float and displayed using that same locale decimal point and locale thousand separator ... well, the only chance for this to work is if the locale decimal point IS already a '.' and the locale thousand separator is ''.
I think this should be enough to test if a value is a float :
Zend_Validate_Float, line 68
if (false===ereg('^[0-9]*\.[0-9]+$', $valueFiltered)){ /* not a float */ }
Attachments
Issue Links
| This issue is duplicated by: | ||||
| ZF-4000 | Zend_Validate_Float always fails in localized environments |
|
|
|
1. |
Fix ZF-3423 | |
|
Adam Kusmierz |
Attention:
You should also take in account that users may have set Zend_Locale to a different locale than the one from setlocale (setlocale is not threadsave).
So we could have system set to french and user setting arabic.
Validate should be able also to verify such.
Easiest solution:
Allow a locale to be set
Use Zend_Locale to normalize the value.