From e1cf987bb828ece2269167272cfd0b50e0d21253 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 9 Apr 2024 11:38:42 +0900 Subject: [PATCH] fix: TypeError in form() --- system/Helpers/form_helper.php | 2 +- tests/system/Helpers/FormHelperTest.php | 38 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 1e3ea4a9152a..2e5b9f7ca576 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -31,7 +31,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s { // If no action is provided then set to the current url if ($action === '') { - $action = current_url(true); + $action = (string) current_url(true); } // If an action is not a full URL then turn it into one elseif (! str_contains($action, '://')) { // If an action has {locale} diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index 2ee32da768fc..cfb58c338932 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -101,21 +101,33 @@ public function testFormOpenWithoutAction(): void { $this->setRequest(); - $before = (new Filters())->globals['before']; - if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) { - $Value = csrf_hash(); - $Name = csrf_token(); - $expected = << - + $expected = <<<'EOH' +
- EOH; - } else { - $expected = <<<'EOH' - + EOH; + $attributes = [ + 'name' => 'form', + 'id' => 'form', + 'method' => 'POST', + ]; + $this->assertSame($expected, form_open('', $attributes)); + } - EOH; - } + public function testFormOpenWithoutActionWithCSRF(): void + { + $this->setRequest(); + + // Sets csrf filter. + $filters = config(Filters::class); + $filters->globals['before'][] = 'csrf'; + service('filters')->initialize(); + + $Value = csrf_hash(); + $Name = csrf_token(); + $expected = << + + EOH; $attributes = [ 'name' => 'form', 'id' => 'form',