Просмотр исходного кода

Fixes #465 -Zend_Currency creates invalid cache ids for values with fractions

Frank Brückner 11 лет назад
Родитель
Сommit
195cbbc540
2 измененных файлов с 45 добавлено и 2 удалено
  1. 21 2
      library/Zend/Locale/Data.php
  2. 24 0
      tests/Zend/Locale/DataTest.php

+ 21 - 2
library/Zend/Locale/Data.php

@@ -327,7 +327,7 @@ class Zend_Locale_Data
         }
 
         $val = urlencode($val);
-        $id = strtr('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
+        $id  = self::_filterCacheId('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val);
         if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
             return unserialize($result);
         }
@@ -976,7 +976,7 @@ class Zend_Locale_Data
             $val = implode('_' , $value);
         }
         $val = urlencode($val);
-        $id = strtr('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
+        $id  = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val);
         if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
             return unserialize($result);
         }
@@ -1581,4 +1581,23 @@ class Zend_Locale_Data
 
         return self::$_cacheTags;
     }
+
+    /**
+     * Filter an ID to only allow valid variable characters
+     *
+     * @param  string $value
+     * @return string
+     */
+    protected static function _filterCacheId($value)
+    {
+        return strtr(
+            $value,
+            array(
+                '-' => '_',
+                '%' => '_',
+                '+' => '_',
+                '.' => '_',
+            )
+        );
+    }
 }

+ 24 - 0
tests/Zend/Locale/DataTest.php

@@ -7230,4 +7230,28 @@ class Zend_Locale_DataTest extends PHPUnit_Framework_TestCase
         $this->assertTrue(is_array($result));
         $this->assertTrue(count($result) > 0);
     }
+
+    /**
+     * @group GH-465
+     */
+    public function testCreateValidCacheIdsInGetContentMethod()
+    {
+        try {
+            $content = Zend_Locale_Data::getContent('de_DE', 'language', 1234.56);
+        } catch (Zend_Cache_Exception $e) {
+            $this->fail($e->getMessage());
+        }
+    }
+
+    /**
+     * @group GH-465
+     */
+    public function testCreateValidCacheIdsInGetListMethod()
+    {
+        try {
+            $list = Zend_Locale_Data::getList('de_DE', 'language', 1234.56);
+        } catch (Zend_Cache_Exception $e) {
+            $this->fail($e->getMessage());
+        }
+    }
 }