diff --git a/system/Session/Session.php b/system/Session/Session.php index ff40a4714e38..3b7dff2d6243 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -503,7 +503,7 @@ public function get(string $key = null) } elseif (empty($_SESSION)) { - return []; + return $key === null ? [] : null; } if (! empty($key)) diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index d22819f469a3..9027088b9ec6 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -129,6 +129,28 @@ public function testGetReturnsNullWhenNotFound() $this->assertNull($session->get('foo')); } + public function testGetReturnsNullWhenNotFoundWithXmlHttpRequest() + { + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest'; + $_SESSION = []; + + $session = $this->getInstance(); + $session->start(); + + $this->assertNull($session->get('foo')); + } + + public function testGetReturnsEmptyArrayWhenWithXmlHttpRequest() + { + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest'; + $_SESSION = []; + + $session = $this->getInstance(); + $session->start(); + + $this->assertEquals([], $session->get()); + } + public function testGetReturnsItemValueisZero() { $_SESSION = [];