Skip to content

Commit 7401b0c

Browse files
committed
Updating Session path handling to fix cases when path = ''.
Test cases added. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8186 3807eeeb-6ff5-0310-8944-8be069107fe0
1 parent d2b4995 commit 7401b0c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cake/libs/session.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,23 @@ function __construct($base = null, $start = true) {
137137
$this->time = time();
138138

139139
if ($start === true) {
140-
$this->host = env('HTTP_HOST');
141-
$this->path = '/';
142-
if (strpos($base, '?') === false && strpos($base, 'index.php') === false) {
140+
if (!empty($base)) {
143141
$this->path = $base;
142+
if (strpos($base, 'index.php') !== false) {
143+
$this->path = str_replace('index.php', '', $base);
144+
}
145+
if (strpos($base, '?') !== false) {
146+
$this->path = str_replace('?', '', $base);
147+
}
144148
}
149+
$this->host = env('HTTP_HOST');
145150

146151
if (strpos($this->host, ':') !== false) {
147152
$this->host = substr($this->host, 0, strpos($this->host, ':'));
148153
}
149-
150154
if (!class_exists('Security')) {
151155
App::import('Core', 'Security');
152156
}
153-
154157
$this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout'));
155158
$this->security = Configure::read('Security.level');
156159
}

cake/tests/cases/libs/session.test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ function setUp() {
7676
function testSessionPath() {
7777
$Session = new CakeSession('/index.php');
7878
$this->assertEqual('/', $Session->path);
79+
80+
$Session = new CakeSession('/sub_dir/index.php');
81+
$this->assertEqual('/sub_dir/', $Session->path);
82+
83+
$Session = new CakeSession('');
84+
$this->assertEqual('/', $Session->path, 'Session path is empty, with "" as $base needs to be / %s');
7985
}
8086
/**
8187
* testCheck method

0 commit comments

Comments
 (0)