Bladeren bron

[ZF-8919] Zend_Validate_Float:

- reverted r17071 which was force by the dev-team for performance reasons
- reason is a PHP bug which accepts floats only in english notation as strings

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21663 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 jaren geleden
bovenliggende
commit
f4b50af3f1
2 gewijzigde bestanden met toevoegingen van 17 en 22 verwijderingen
  1. 6 21
      library/Zend/Validate/Float.php
  2. 11 1
      tests/Zend/Validate/FloatTest.php

+ 6 - 21
library/Zend/Validate/Float.php

@@ -76,9 +76,7 @@ class Zend_Validate_Float extends Zend_Validate_Abstract
             }
         }
 
-        if ($locale !== null) {
-            $this->setLocale($locale);
-        }
+        $this->setLocale($locale);
     }
 
     /**
@@ -121,27 +119,14 @@ class Zend_Validate_Float extends Zend_Validate_Abstract
         }
 
         $this->_setValue($value);
-        if ($this->_locale === null) {
-            $locale        = localeconv();
-            $valueFiltered = str_replace($locale['thousands_sep'], '', (string) $value);
-            $valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered);
-
-            if (strval(floatval($valueFiltered)) != $valueFiltered) {
-                $this->_error(self::NOT_FLOAT);
-                return false;
-            }
-
-        } else {
-            try {
-                if (!Zend_Locale_Format::isFloat($value, array('locale' => 'en')) &&
-                    !Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
-                    $this->_error(self::NOT_FLOAT);
-                    return false;
-                }
-            } catch (Zend_Locale_Exception $e) {
+        try {
+            if (!Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
                 $this->_error(self::NOT_FLOAT);
                 return false;
             }
+        } catch (Zend_Locale_Exception $e) {
+            $this->_error(self::NOT_FLOAT);
+            return false;
         }
 
         return true;

+ 11 - 1
tests/Zend/Validate/FloatTest.php

@@ -90,7 +90,6 @@ class Zend_Validate_FloatTest extends PHPUnit_Framework_TestCase
             array(1.00, true),
             array(0.01, true),
             array(-0.1, true),
-            array('10.1', true),
             array(1, true),
             array('not a float', false),
             );
@@ -145,6 +144,7 @@ class Zend_Validate_FloatTest extends PHPUnit_Framework_TestCase
         setlocale(LC_ALL, 'de');
         $valid = new Zend_Validate_Float();
         $this->assertTrue($valid->isValid(123,456));
+        $this->assertTrue($valid->isValid('123,456'));
     }
 
     /**
@@ -166,4 +166,14 @@ class Zend_Validate_FloatTest extends PHPUnit_Framework_TestCase
         $valid = new Zend_Validate_Float();
         $this->assertTrue($valid->isValid(10.5));
     }
+
+    /**
+     * @ZF-8919
+     */
+    public function testPhpLocaleDeStringType()
+    {
+        setlocale(LC_NUMERIC, 'de_AT');
+        $valid = new Zend_Validate_Float();
+        $this->assertTrue($valid->isValid('1,3'));
+    }
 }