Allowing spaces in session keys (Ticket #2639)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5208 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-05-27 04:10:29 +00:00
parent f916745c87
commit 07006c9e4a
3 changed files with 46 additions and 19 deletions

View file

@ -181,13 +181,13 @@ class CakeSession extends Object {
* @access private
*/
function __sessionVarNames($name) {
if (is_string($name) && preg_match("/^[0-9a-zA-Z._-]+$/", $name)) {
if (is_string($name) && preg_match("/^[ 0-9a-zA-Z._-]*$/", $name)) {
if (strpos($name, ".")) {
$names = explode(".", $name);
} else {
$names = array($name);
}
$expression="\$_SESSION";
$expression = "\$_SESSION";
foreach($names as $item) {
$expression .= is_numeric($item) ? "[$item]" : "['$item']";
}
@ -538,7 +538,7 @@ class CakeSession extends Object {
* @access private
*/
function __validateKeys($name) {
if (is_string($name) && preg_match("/^[0-9a-zA-Z._-]+$/", $name)) {
if (is_string($name) && preg_match("/^[ 0-9a-zA-Z._-]*$/", $name)) {
return $name;
}
$this->__setError(3, "$name is not a string");

View file

@ -52,19 +52,28 @@ class SessionTest extends UnitTestCase {
}
function testCheckingSavedEmpty() {
$this->Session->write('SessionTestCase', 0);
$this->assertTrue($this->Session->write('SessionTestCase', 0));
$this->assertTrue($this->Session->check('SessionTestCase'));
$this->assertTrue($this->Session->write('SessionTestCase', '0'));
$this->assertTrue($this->Session->check('SessionTestCase'));
$this->Session->write('SessionTestCase', '0');
$this->assertTrue($this->Session->write('SessionTestCase', false));
$this->assertTrue($this->Session->check('SessionTestCase'));
$this->Session->write('SessionTestCase', false);
$this->assertTrue($this->Session->check('SessionTestCase'));
$this->Session->write('SessionTestCase', null);
$this->assertTrue($this->Session->write('SessionTestCase', null));
$this->assertFalse($this->Session->check('SessionTestCase'));
}
function testCheckKeyWithSpaces() {
$this->assertTrue($this->Session->write('Session Test', "test"));
$this->assertEqual($this->Session->check('Session Test'), 'test');
$this->Session->del('Session Test');
$this->assertTrue($this->Session->write('Session Test.Test Case', "test"));
$this->assertTrue($this->Session->check('Session Test.Test Case'));
}
function testReadingSavedEmpty() {
$this->Session->write('SessionTestCase', 0);
$this->assertEqual($this->Session->read('SessionTestCase'), 0);
@ -79,7 +88,7 @@ class SessionTest extends UnitTestCase {
$this->Session->write('SessionTestCase', null);
$this->assertEqual($this->Session->read('SessionTestCase'), null);
}
function tearDown() {
$this->Session->del('SessionTestCase');
unset($this->Session);

View file

@ -134,19 +134,13 @@ class SetTest extends UnitTestCase {
);
$this->assertIdentical(Set::merge($a, $b, $c), $expected);
// Test that passing in an empty array does not mess things up
$this->assertIdentical(Set::merge($a, $b, array(), $c), $expected);
// Create a new Set instance from the $a array
$Set =& new Set($a);
// Merge $b, an empty array and $c over it
$r = $Set->merge($b, array(), $c);
// And test that it produces the same result as a static call would
$this->assertIdentical($r, $expected);
// And also updates it's own value property
$this->assertIdentical($Set->value, $expected);
// Let the garbage collector eat the Set instance
unset($Set);
$Set =& new Set();
@ -156,9 +150,7 @@ class SetTest extends UnitTestCase {
$SetC =& new Set($c);
$r = $Set->merge($SetA, $SetB, $SetC);
// And test that it produces the same result as a static call would
$this->assertIdentical($r, $expected);
// And also updates it's own value property
$this->assertIdentical($Set->value, $expected);
}
@ -257,6 +249,32 @@ class SetTest extends UnitTestCase {
);
$this->assertIdentical($result, $expected);
}
function testCheck() {
$set = new Set(array(
'My Index 1' => array('First' => 'The first item')
));
$this->assertTrue($set->check('My Index 1.First'));
$set = new Set(array(
'My Index 1' => array('First' => array('Second' => array('Third' => array('Fourth' => 'Heavy. Nesting.'))))
));
$this->assertTrue($set->check('My Index 1.First.Second'));
$this->assertTrue($set->check('My Index 1.First.Second.Third'));
$this->assertTrue($set->check('My Index 1.First.Second.Third.Fourth'));
}
function testWritingWithFunkyKeys() {
$set = new Set();
$set->insert('Session Test', "test");
$this->assertEqual($set->extract('Session Test'), 'test');
$set->remove('Session Test');
$this->assertFalse($set->check('Session Test'));
$this->assertTrue($set->insert('Session Test.Test Case', "test"));
$this->assertTrue($set->check('Session Test.Test Case'));
}
}
?>