Allowing returning numeric 0 from read

This commit is contained in:
Larry E. Masters 2015-12-28 23:26:06 -05:00
parent a02fb9e771
commit a966e46545
4 changed files with 8 additions and 2 deletions

View file

@ -53,7 +53,8 @@ class CacheSession implements CakeSessionHandlerInterface {
*/
public function read($id) {
$data = Cache::read($id, Configure::read('Session.handler.config'));
if (empty($data)) {
if (!is_numeric($data) && empty($data)) {
return '';
}
return $data;

View file

@ -92,7 +92,7 @@ class DatabaseSession implements CakeSessionHandlerInterface {
'conditions' => array($this->_model->alias . '.' . $this->_model->primaryKey => $id)
));
if (empty($row[$this->_model->alias]['data'])) {
if (!is_numeric($row[$this->_model->alias]['data']) && empty($row[$this->_model->alias]['data'])) {
return '';
}

View file

@ -104,6 +104,8 @@ class CacheSessionTest extends CakeTestCase {
public function testRead() {
$this->storage->write('test_one', 'Some other value');
$this->assertEquals('Some other value', $this->storage->read('test_one'), 'Incorrect value.');
$this->storage->write('test_two', 0);
$this->assertEquals(0, $this->storage->read('test_two'));
}
/**

View file

@ -144,7 +144,10 @@ class DatabaseSessionTest extends CakeTestCase {
public function testRead() {
$this->storage->write('foo', 'Some value');
$this->assertEquals($this->storage->read('foo'), 'Some value');
$this->storage->write('bar', 0);
$this->assertEquals(0, $this->storage->read('bar'));
$this->assertSame('', $this->storage->read('made up value'));
}
/**