From a63474a54d8fc481db58b9c89772be85110afde9 Mon Sep 17 00:00:00 2001 From: predominant Date: Thu, 22 Jul 2010 18:42:56 +1000 Subject: [PATCH] Add test for path containing question, and fix assignment of CakeSession::path --- cake/libs/cake_session.php | 37 ++++++++------------- cake/tests/cases/libs/cake_session.test.php | 20 ++++++++++- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index 7c00efd9e..8ccb95fdd 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -144,6 +144,7 @@ class CakeSession { if ($start === true) { self::_setPath($base); self::_setHost(); + self::start(); } if (isset($_SESSION) || $start === true) { self::$sessionTime = self::$time + (Security::inactiveMins() * Configure::read('Session.timeout')); @@ -162,14 +163,13 @@ class CakeSession { self::$path = '/'; return; } - - self::$path = $base; if (strpos($base, 'index.php') !== false) { - self::$path = str_replace('index.php', '', $base); + $base = str_replace('index.php', '', $base); } if (strpos($base, '?') !== false) { - self::$path = str_replace('?', '', $base); + $base = str_replace('?', '', $base); } + self::$path = $base; } /** @@ -222,28 +222,19 @@ class CakeSession { * @return boolean True if session was started */ public static function start() { - if (!self::started()) { - session_write_close(); - self::__initSession(); - self::_startSession(); + if (self::started()) { + return true; } - return self::started(); - } -/** - * Begins the session if it hasn't already been started, and runs _checkValid which sets up some - * session tampering settings. - * - * @return void - */ - public static function begin() { - if (self::started() === false) { - if (!self::id() && self::start()) { - self::_checkValid(); - } else { - self::start(); - } + session_write_close(); + self::__initSession(); + self::_startSession(); + $started = self::started(); + + if (!self::id() && $started) { + self::_checkValid(); } + self::$error = array(); return self::started(); } diff --git a/cake/tests/cases/libs/cake_session.test.php b/cake/tests/cases/libs/cake_session.test.php index 77d8b9b1c..edc07f40b 100644 --- a/cake/tests/cases/libs/cake_session.test.php +++ b/cake/tests/cases/libs/cake_session.test.php @@ -96,17 +96,35 @@ class CakeSessionTest extends CakeTestCase { * @return void */ function testSessionPath() { -// $Session = new CakeSession('/index.php'); TestCakeSession::init('/index.php'); $this->assertEqual('/', TestCakeSession::$path); TestCakeSession::init('/sub_dir/index.php'); $this->assertEqual('/sub_dir/', TestCakeSession::$path); + } +/** + * testCakeSessionPathEmpty + * + * @access public + * @return void + */ + function testCakeSessionPathEmpty() { TestCakeSession::init(''); $this->assertEqual('/', TestCakeSession::$path, 'Session path is empty, with "" as $base needs to be / %s'); } +/** + * testCakeSessionPathContainsParams + * + * @access public + * @return void + */ + function testCakeSessionPathContainsQuestion() { + TestCakeSession::init('/index.php?'); + $this->assertEqual('/', TestCakeSession::$path); + } + /** * testCheck method *