Fixing issue where empty session id's would cause duplicate key errors. Empty session id sessions are no longer saved. Fixes #1450

This commit is contained in:
mark_story 2011-01-18 08:14:47 -05:00
parent b0d4951184
commit cfce0e45d3
2 changed files with 34 additions and 0 deletions

View file

@ -751,6 +751,9 @@ class CakeSession extends Object {
* @access private
*/
function __write($id, $data) {
if (!$id) {
return false;
}
$expires = time() + Configure::read('Session.timeout') * Security::inactiveMins();
$model =& ClassRegistry::getObject('Session');
$return = $model->save(array($model->primaryKey => $id) + compact('data', 'expires'));

View file

@ -474,4 +474,35 @@ class CakeSessionTest extends CakeTestCase {
$this->setUp();
}
/**
* testReadAndWriteWithDatabaseStorage method
*
* @access public
* @return void
*/
function testDatabaseStorageEmptySessionId() {
unset($_SESSION);
session_destroy();
Configure::write('Session.table', 'sessions');
Configure::write('Session.model', 'Session');
Configure::write('Session.database', 'test_suite');
Configure::write('Session.save', 'database');
$this->setUp();
$id = $this->Session->id();
$this->Session->id = '';
session_id('');
$this->Session->write('SessionTestCase', 'This is a Test');
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');
session_write_close();
unset($_SESSION);
ini_set('session.save_handler', 'files');
Configure::write('Session.save', 'php');
session_id($id);
$this->setUp();
}
}