Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 195cbbc

Browse files
committed
Fixes zendframework#465 -Zend_Currency creates invalid cache ids for values with fractions
1 parent 3361890 commit 195cbbc

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

library/Zend/Locale/Data.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public static function getList($locale, $path, $value = false)
327327
}
328328

329329
$val = urlencode($val);
330-
$id = strtr('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
330+
$id = self::_filterCacheId('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val);
331331
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
332332
return unserialize($result);
333333
}
@@ -976,7 +976,7 @@ public static function getContent($locale, $path, $value = false)
976976
$val = implode('_' , $value);
977977
}
978978
$val = urlencode($val);
979-
$id = strtr('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_'));
979+
$id = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val);
980980
if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) {
981981
return unserialize($result);
982982
}
@@ -1581,4 +1581,23 @@ private static function _getTagSupportForCache()
15811581

15821582
return self::$_cacheTags;
15831583
}
1584+
1585+
/**
1586+
* Filter an ID to only allow valid variable characters
1587+
*
1588+
* @param string $value
1589+
* @return string
1590+
*/
1591+
protected static function _filterCacheId($value)
1592+
{
1593+
return strtr(
1594+
$value,
1595+
array(
1596+
'-' => '_',
1597+
'%' => '_',
1598+
'+' => '_',
1599+
'.' => '_',
1600+
)
1601+
);
1602+
}
15841603
}

tests/Zend/Locale/DataTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7230,4 +7230,28 @@ public function testGetListEmptyTypeReturnsNonemptyArray()
72307230
$this->assertTrue(is_array($result));
72317231
$this->assertTrue(count($result) > 0);
72327232
}
7233+
7234+
/**
7235+
* @group GH-465
7236+
*/
7237+
public function testCreateValidCacheIdsInGetContentMethod()
7238+
{
7239+
try {
7240+
$content = Zend_Locale_Data::getContent('de_DE', 'language', 1234.56);
7241+
} catch (Zend_Cache_Exception $e) {
7242+
$this->fail($e->getMessage());
7243+
}
7244+
}
7245+
7246+
/**
7247+
* @group GH-465
7248+
*/
7249+
public function testCreateValidCacheIdsInGetListMethod()
7250+
{
7251+
try {
7252+
$list = Zend_Locale_Data::getList('de_DE', 'language', 1234.56);
7253+
} catch (Zend_Cache_Exception $e) {
7254+
$this->fail($e->getMessage());
7255+
}
7256+
}
72337257
}

0 commit comments

Comments
 (0)