Browse Source

[GENERIC] Zend_Validate_Int/Zend_Validate_Float:

- using OS number detection (old behaviour) when no locale has been set

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17071 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 years ago
parent
commit
0116535122
2 changed files with 42 additions and 14 deletions
  1. 21 7
      library/Zend/Validate/Float.php
  2. 21 7
      library/Zend/Validate/Int.php

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

@@ -57,7 +57,9 @@ class Zend_Validate_Float extends Zend_Validate_Abstract
      */
     public function __construct($locale = null)
     {
-        $this->setLocale($locale);
+        if ($locale !== null) {
+            $this->setLocale($locale);
+        }
     }
 
     /**
@@ -96,15 +98,27 @@ class Zend_Validate_Float extends Zend_Validate_Abstract
         }
 
         $this->_setValue($value);
-        try {
-            if (!Zend_Locale_Format::isFloat($value, array('locale' => 'en')) &&
-                !Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
+        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();
+                return false;
+            }
+
+        } else {
+            try {
+                if (!Zend_Locale_Format::isFloat($value, array('locale' => 'en')) &&
+                    !Zend_Locale_Format::isFloat($value, array('locale' => $this->_locale))) {
+                    $this->_error();
+                    return false;
+                }
+            } catch (Zend_Locale_Exception $e) {
                 $this->_error();
                 return false;
             }
-        } catch (Zend_Locale_Exception $e) {
-            $this->_error();
-            return false;
         }
 
         return true;

+ 21 - 7
library/Zend/Validate/Int.php

@@ -57,7 +57,9 @@ class Zend_Validate_Int extends Zend_Validate_Abstract
      */
     public function __construct($locale = null)
     {
-        $this->setLocale($locale);
+        if ($locale !== null) {
+            $this->setLocale($locale);
+        }
     }
 
     /**
@@ -96,15 +98,27 @@ class Zend_Validate_Int extends Zend_Validate_Abstract
         }
 
         $this->_setValue($value);
-        try {
-            if (!Zend_Locale_Format::isInteger($value, array('locale' => 'en')) &&
-                !Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) {
+        if ($this->_locale === null) {
+            $locale        = localeconv();
+            $valueFiltered = str_replace($locale['decimal_point'], '.', $valueString);
+            $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered);
+
+            if (strval(intval($valueFiltered)) != $valueFiltered) {
+                $this->_error();
+                return false;
+            }
+
+        } else {
+            try {
+                if (!Zend_Locale_Format::isInteger($value, array('locale' => 'en')) &&
+                    !Zend_Locale_Format::isInteger($value, array('locale' => $this->_locale))) {
+                    $this->_error();
+                    return false;
+                }
+            } catch (Zend_Locale_Exception $e) {
                 $this->_error();
                 return false;
             }
-        } catch (Zend_Locale_Exception $e) {
-            $this->_error();
-            return false;
         }
 
         return true;