From 74b655d3fcb28db877d839c75f2f3f98b41448cd Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 18 Jul 2018 21:15:56 +1200 Subject: [PATCH] Fix tests on unset session data Thanks Robbie! --- src/Control/Director.php | 2 +- src/Control/Session.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Control/Director.php b/src/Control/Director.php index 79622d213..6e7aef593 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -206,7 +206,7 @@ class Director implements TemplateGlobalProvider if ($session instanceof Session) { // Note: If passing $session as object, ensure that changes are written back // This is important for classes such as FunctionalTest which emulate cross-request persistence - $newVars['_SESSION'] = $sessionArray = $session->getAll(); + $newVars['_SESSION'] = $sessionArray = $session->getAll() ?: []; $finally[] = function () use ($session, $sessionArray) { if (isset($_SESSION)) { // Set new / updated keys diff --git a/src/Control/Session.php b/src/Control/Session.php index 17a2c295a..f9f95d1cf 100644 --- a/src/Control/Session.php +++ b/src/Control/Session.php @@ -262,8 +262,8 @@ class Session public function requestContainsSessionId(HTTPRequest $request) { $secure = Director::is_https($request) && $this->config()->get('cookie_secure'); - $name = $secure ? $this->config()->get('cookie_name_secure') : session_name(); - return (bool)Cookie::get($name); + $name = $secure ? $this->config()->get('cookie_name_secure') : session_name(); + return (bool)Cookie::get($name); } /** @@ -330,9 +330,9 @@ class Session $this->recursivelyApply((array)$this->data, $data); } else { // Use in-memory data if the session is lazy started - $data = isset($this->data) ? $this->data : []; + $data = $this->data; } - $this->data = $data; + $this->data = $data ?: []; } else { $this->data = []; } @@ -615,6 +615,7 @@ class Session */ protected function recursivelyApplyChanges($changes, $source, &$destination) { + $source = $source ?: []; foreach ($changes as $key => $changed) { if ($changed === true) { // Determine if replacement or removal