Skip to content
This repository
Browse code

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
  • Loading branch information...
commit 7401b0c70f103f16afa51fd720be31d09d833a68 1 parent d2b4995
Mark Story authored June 03, 2009
13  cake/libs/session.php
@@ -137,20 +137,23 @@ function __construct($base = null, $start = true) {
137 137
 		$this->time = time();
138 138
 
139 139
 		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)) {
143 141
 				$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
+				}
144 148
 			}
  149
+			$this->host = env('HTTP_HOST');
145 150
 
146 151
 			if (strpos($this->host, ':') !== false) {
147 152
 				$this->host = substr($this->host, 0, strpos($this->host, ':'));
148 153
 			}
149  
-
150 154
 			if (!class_exists('Security')) {
151 155
 				App::import('Core', 'Security');
152 156
 			}
153  
-
154 157
 			$this->sessionTime = $this->time + (Security::inactiveMins() * Configure::read('Session.timeout'));
155 158
 			$this->security = Configure::read('Security.level');
156 159
 		}
6  cake/tests/cases/libs/session.test.php
@@ -76,6 +76,12 @@ function setUp() {
76 76
 	function testSessionPath() {
77 77
 		$Session = new CakeSession('/index.php');
78 78
 		$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');
79 85
 	}
80 86
 /**
81 87
  * testCheck method

0 notes on commit 7401b0c

Please sign in to comment.
Something went wrong with that request. Please try again.