From 113e2cda77ea1894b523f393c496bd95069922d4 Mon Sep 17 00:00:00 2001 From: Instrye Date: Wed, 25 Mar 2020 10:15:02 +0800 Subject: [PATCH] fix. session key can't have dot --- system/Session/Session.php | 2 +- tests/system/Session/SessionTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/system/Session/Session.php b/system/Session/Session.php index 3f9cdc240a40..0749580ccac6 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -499,7 +499,7 @@ public function set($data, $value = null) */ public function get(string $key = null) { - if (! empty($key) && ! is_null($value = dot_array_search($key, $_SESSION ?? []))) + if (! empty($key) && (! is_null($value = isset($_SESSION[$key]) ? $_SESSION[$key] : null) || ! is_null($value = dot_array_search($key, $_SESSION ?? [])))) { return $value; } diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index 9027088b9ec6..a4f36aa36556 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -532,4 +532,14 @@ public function testGetTempdataKeys() $this->assertEquals(['foo', 'bar'], $session->getTempKeys()); } + + public function testGetDotKey() + { + $session = $this->getInstance(); + $session->start(); + + $session->set('test.1', 'value'); + + $this->assertEquals('value', $session->get('test.1')); + } }