mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Add test for path containing question, and fix assignment of CakeSession::path
This commit is contained in:
parent
f5565895e9
commit
a63474a54d
2 changed files with 33 additions and 24 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue