Issue Details (XML | Word | Printable)

Key: ZF-6175
Type: Bug Bug
Status: Resolved Resolved
Resolution: Duplicate
Priority: Minor Minor
Assignee: Thomas Weidner
Reporter: Danne Lundqvist
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Google issue summary
Zend Framework

Zend_Validate_Float fails in localized environment

Created: 01/Apr/09 03:21 AM   Updated: 04/Apr/09 12:54 PM   Resolved: 04/Apr/09 12:54 PM
Return to search "Fixed in 1.5.1"
Component/s: Zend_Validate
Affects Version/s: 1.7.6, 1.7.7, 1.7.8
Fix Version/s: 1.8.0

Time Tracking:
Not Specified


 Description  « Hide

Floats and thus the function floatval() used to test filtered value in Zend_Validate_Float::isValid() is locale aware and return value with localized decimal_point. Thus the test will always fail when a locale is set which uses a decimal point other than ".". Tested with PHP 5.2.6.2.

When...
setlocale(LC_ALL, 'sv_SE.UTF-8');
$value = 10.5;

...this will always fail as it results in a comparison between "10,5" and "10.5".
if (strval(floatval($valueFiltered)) != $valueFiltered) {
$this->_error();
return false;
}

Proposed solution

list($num, $dec) = explode('.', $valueFiltered);
if (strval(intval($num)) != $num || strval(intval($dec)) != $dec) {
$this->_error();
return false;
}

There are also no unit test Zend_Validate_Float with a locale other than default.



Thomas Weidner added a comment - 04/Apr/09 12:54 PM

This new feature has been added 3 months ago.
It will be released with 1.8.