Zend Framework

Zend_Validate_Float fails in localized environment

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: 1.7.6, 1.7.7, 1.7.8
  • Fix Version/s: 1.8.0
  • Component/s: Zend_Validate
  • Labels:
    None

Description

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.

Activity

Hide
Thomas Weidner added a comment -

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

Show
Thomas Weidner added a comment - This new feature has been added 3 months ago. It will be released with 1.8.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: