diff --git a/src/Network/Session.php b/src/Network/Session.php index 85a2554a1ed..97c585ddc1d 100644 --- a/src/Network/Session.php +++ b/src/Network/Session.php @@ -355,10 +355,6 @@ public function started() */ public function check($name = null) { - if (empty($name)) { - return false; - } - if ($this->_hasSession() && !$this->started()) { $this->start(); } @@ -379,10 +375,6 @@ public function check($name = null) */ public function read($name = null) { - if (empty($name) && $name !== null) { - return null; - } - if ($this->_hasSession() && !$this->started()) { $this->start(); } @@ -427,10 +419,6 @@ public function consume($name) */ public function write($name, $value = null) { - if (empty($name)) { - return; - } - if (!$this->started()) { $this->start(); } diff --git a/src/Utility/Hash.php b/src/Utility/Hash.php index c1439d3ce14..4680120f045 100644 --- a/src/Utility/Hash.php +++ b/src/Utility/Hash.php @@ -53,7 +53,7 @@ public static function get($data, $path, $default = null) ); } - if (empty($data) || $path === null || $path === '') { + if (empty($data) || $path === null) { return $default; } diff --git a/tests/TestCase/Network/SessionTest.php b/tests/TestCase/Network/SessionTest.php index 0b86e6f67fc..ebff6a90884 100644 --- a/tests/TestCase/Network/SessionTest.php +++ b/tests/TestCase/Network/SessionTest.php @@ -162,11 +162,11 @@ public function testCheck() } /** - * testSimpleRead method + * test read with simple values * * @return void */ - public function testSimpleRead() + public function testReadSimple() { $session = new Session(); $session->write('testing', '1,2,3'); @@ -181,7 +181,7 @@ public function testSimpleRead() $this->assertEquals(['1' => 'one', '2' => 'two', '3' => 'three'], $result); $result = $session->read(); - $this->assertTrue(isset($result['testing'])); + $this->assertArrayHasKey('testing', $result); $session->write('This.is.a.deep.array.my.friend', 'value'); $result = $session->read('This.is.a.deep.array'); @@ -200,7 +200,22 @@ public function testReadEmpty() } /** - * test writing a hash of values/ + * Test writing simple keys + * + * @return void + */ + public function testWriteSimple() + { + $session = new Session(); + $session->write('', 'empty'); + $this->assertEquals('empty', $session->read('')); + + $session->write('Simple', ['values']); + $this->assertEquals(['values'], $session->read('Simple')); + } + + /** + * test writing a hash of values * * @return void */ @@ -334,6 +349,19 @@ public function testDelete() $this->assertFalse($session->check('Clearing')); } + /** + * test delete + * + * @return void + */ + public function testDeleteEmptyString() + { + $session = new Session(); + $session->write('', 'empty string'); + $session->delete(''); + $this->assertFalse($session->check('')); + } + /** * testDestroy method * @@ -421,6 +449,10 @@ public function testKeyExploit() public function testReadingSavedEmpty() { $session = new Session(); + $session->write('', 'empty string'); + $this->assertTrue($session->check('')); + $this->assertEquals('empty string', $session->read('')); + $session->write('SessionTestCase', 0); $this->assertEquals(0, $session->read('SessionTestCase')); diff --git a/tests/TestCase/Utility/HashTest.php b/tests/TestCase/Utility/HashTest.php index 197f4673577..005088ccc6b 100644 --- a/tests/TestCase/Utility/HashTest.php +++ b/tests/TestCase/Utility/HashTest.php @@ -393,6 +393,20 @@ public function testGet() $this->assertEquals(1, Hash::get(new ArrayObject($data), 'a.b.c.d')); } + /** + * Test that get() can extract '' key data. + * + * @return void + */ + public function testGetEmptyKey() + { + $data = [ + '' => 'some value' + ]; + $result = Hash::get($data, ''); + $this->assertSame($data[''], $result); + } + /** * Test get() for invalid $data type *