mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Enabling Cache::write() to handle 'empty' values, fixes #4090
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6549 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
bd929c45df
commit
35397debc8
2 changed files with 30 additions and 10 deletions
6
cake/libs/cache/file.php
vendored
6
cake/libs/cache/file.php
vendored
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
*/
|
||||
if (!class_exists('File')) {
|
||||
uses ('File');
|
||||
App::import('Core', 'File');
|
||||
}
|
||||
/**
|
||||
* File Storage engine for cache
|
||||
|
@ -115,7 +115,7 @@ class FileEngine extends CacheEngine {
|
|||
* @access public
|
||||
*/
|
||||
function write($key, &$data, $duration) {
|
||||
if (empty($data) || !$this->__init) {
|
||||
if ($data === '' || !$this->__init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ class FileEngine extends CacheEngine {
|
|||
}
|
||||
$data = $this->__File->read(true);
|
||||
|
||||
if (!empty($data) && !empty($this->settings['serialize'])) {
|
||||
if ($data !== '' && !empty($this->settings['serialize'])) {
|
||||
$data = stripslashes($data);
|
||||
$data = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $data);
|
||||
$data = unserialize($data);
|
||||
|
|
|
@ -56,14 +56,34 @@ class CacheTest extends UnitTestCase {
|
|||
function testInitSettings() {
|
||||
Cache::engine('File', array('path' => TMP . 'tests'));
|
||||
$settings = Cache::settings();
|
||||
$expecting = array('duration'=> 3600,
|
||||
'probability' => 100,
|
||||
'path'=> TMP . 'tests',
|
||||
'prefix'=> 'cake_',
|
||||
'lock' => false,
|
||||
'serialize'=> true,
|
||||
);
|
||||
$expecting = array(
|
||||
'duration'=> 3600,
|
||||
'probability' => 100,
|
||||
'path'=> TMP . 'tests',
|
||||
'prefix'=> 'cake_',
|
||||
'lock' => false,
|
||||
'serialize'=> true
|
||||
);
|
||||
$this->assertEqual($settings, $expecting);
|
||||
}
|
||||
|
||||
function testWriteEmptyValues() {
|
||||
return;
|
||||
Cache::engine('File', array('path' => TMP . 'tests'));
|
||||
Cache::write('App.falseTest', false);
|
||||
$this->assertIdentical(Cache::read('App.falseTest'), false);
|
||||
|
||||
Cache::write('App.trueTest', true);
|
||||
$this->assertIdentical(Cache::read('App.trueTest'), true);
|
||||
|
||||
Cache::write('App.nullTest', null);
|
||||
$this->assertIdentical(Cache::read('App.nullTest'), null);
|
||||
|
||||
Cache::write('App.zeroTest', 0);
|
||||
$this->assertIdentical(Cache::read('App.zeroTest'), 0);
|
||||
|
||||
Cache::write('App.zeroTest2', '0');
|
||||
$this->assertIdentical(Cache::read('App.zeroTest2'), '0');
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue