diff --git a/boot/helpers.php b/boot/helpers.php index ccd888e..62dc8b8 100644 --- a/boot/helpers.php +++ b/boot/helpers.php @@ -156,7 +156,7 @@ function old(?string $key, bool $escape = true) : mixed { App::session()->activate(); $data = App::request()->getRedirectData($key); - if ($escape) { + if ($data !== null && $escape) { $data = is_scalar($data) || (is_object($data) && method_exists($data, '__toString')) ? esc((string) $data) : ''; diff --git a/tests/boot/HelpersTest.php b/tests/boot/HelpersTest.php index 6f58c90..6a6fb67 100644 --- a/tests/boot/HelpersTest.php +++ b/tests/boot/HelpersTest.php @@ -100,6 +100,7 @@ public function testOld() : void 'xss' => '', ]); App::session()->stop(); + self::assertNull(old('unknown')); self::assertSame('', old('user')); self::assertSame('John Doe', old('user[name]')); self::assertSame(