mirror of
https://github.com/yiisoft/yii2.git
synced 2025-10-30 18:17:00 +08:00
array union in controllers
! fix issue when handling parameter with string type, add according test
This commit is contained in:
@ -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];
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user