From 848a90dea8408e51164147bc41fac412febd24d0 Mon Sep 17 00:00:00 2001 From: Chris Reichel Date: Mon, 19 May 2025 12:21:45 +0200 Subject: [PATCH] array union in controllers ! fix issue when handling parameter with string type, add according test --- framework/web/Controller.php | 3 +++ tests/framework/web/ControllerTest.php | 7 ++++--- tests/framework/web/FakePhp7Controller.php | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/framework/web/Controller.php b/framework/web/Controller.php index b45a7fbd04..1b98d28ee7 100644 --- a/framework/web/Controller.php +++ b/framework/web/Controller.php @@ -217,6 +217,9 @@ class Controller extends \yii\base\Controller return ['', true]; } + if ($typeName === 'string') { + return [$param, true]; + } $filterResult = $this->filterParamByType($param, $typeName); return [$filterResult, $filterResult !== null]; } diff --git a/tests/framework/web/ControllerTest.php b/tests/framework/web/ControllerTest.php index 1e930399bc..aaff03f3b5 100644 --- a/tests/framework/web/ControllerTest.php +++ b/tests/framework/web/ControllerTest.php @@ -235,16 +235,17 @@ class ControllerTest extends TestCase $aksi1 = new InlineAction('aksi1', $this->controller, 'actionAksi1'); - $params = ['foo' => '100', 'bar' => null, 'true' => 'on', 'false' => 'false']; - list($foo, $bar, $true, $false) = $this->controller->bindActionParams($aksi1, $params); + $params = ['foo' => '100', 'bar' => null, 'true' => 'on', 'false' => 'false', 'string' => 'strong']; + list($foo, $bar, $true, $false, $string) = $this->controller->bindActionParams($aksi1, $params); $this->assertSame(100, $foo); $this->assertSame(null, $bar); $this->assertSame(true, $true); $this->assertSame(false, $false); + $this->assertSame('strong', $string); // allow nullable argument to be set to empty string (as null) // https://github.com/yiisoft/yii2/issues/18450 - $params = ['foo' => 100, 'bar' => '', 'true' => true, 'false' => true]; + $params = ['foo' => 100, 'bar' => '', 'true' => true, 'false' => true, 'string' => 'strong']; list(, $bar) = $this->controller->bindActionParams($aksi1, $params); $this->assertSame(null, $bar); diff --git a/tests/framework/web/FakePhp7Controller.php b/tests/framework/web/FakePhp7Controller.php index 74008f49fa..1ab5c55708 100644 --- a/tests/framework/web/FakePhp7Controller.php +++ b/tests/framework/web/FakePhp7Controller.php @@ -17,7 +17,7 @@ class FakePhp7Controller extends Controller { public $enableCsrfValidation = false; - public function actionAksi1(int $foo, ?float $bar, bool $true, bool $false) + public function actionAksi1(int $foo, ?float $bar, bool $true, bool $false, string $string) { }