Fix #18859: Fix yii\web\Controller::bindInjectedParams() to not throw error when argument of ReflectionUnionType type is passed

This commit is contained in:
Bizley
2023-05-31 20:30:45 +02:00
committed by GitHub
parent f6bb12091b
commit 80a18ad6ba
4 changed files with 52 additions and 1 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.49 under development
------------------------
- Bug #18859: Fix `yii\web\Controller::bindInjectedParams()` to not throw error when argument of `ReflectionUnionType` type is passed (bizley)
- Enh #19841: Allow jQuery 3.7 to be installed (wouter90)

View File

@ -141,6 +141,7 @@ class Controller extends \yii\base\Controller
} elseif (
PHP_VERSION_ID >= 70000
&& ($type = $param->getType()) !== null
&& method_exists($type, 'isBuiltin')
&& $type->isBuiltin()
&& ($params[$name] !== null || !$type->allowsNull())
) {

View File

@ -10,7 +10,6 @@ namespace yiiunit\framework\web;
use RuntimeException;
use Yii;
use yii\base\InlineAction;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
use yii\web\Response;
use yii\web\ServerErrorHttpException;
@ -332,4 +331,34 @@ class ControllerTest extends TestCase
$this->assertEquals($this->controller->redirect(['//controller/index', 'id_1' => 3, 'id_2' => 4])->headers->get('location'), '/index.php?r=controller%2Findex&id_1=3&id_2=4');
$this->assertEquals($this->controller->redirect(['//controller/index', 'slug' => 'äöüß!"§$%&/()'])->headers->get('location'), '/index.php?r=controller%2Findex&slug=%C3%A4%C3%B6%C3%BC%C3%9F%21%22%C2%A7%24%25%26%2F%28%29');
}
public function testUnionBindingActionParams()
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Can not be tested on PHP < 8.0');
return;
}
// Use the PHP80 controller for this test
$this->controller = new FakePhp80Controller('fake', new \yii\web\Application([
'id' => 'app',
'basePath' => __DIR__,
'components' => [
'request' => [
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
'scriptFile' => __DIR__ . '/index.php',
'scriptUrl' => '/index.php',
],
],
]));
$this->mockWebApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'actionInjection');
$params = ['arg' => 'test', 'second' => 1];
$args = $this->controller->bindActionParams($injectionAction, $params);
$this->assertSame('test', $args[0]);
$this->assertSame(1, $args[1]);
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace yiiunit\framework\web;
use yii\web\Controller;
class FakePhp80Controller extends Controller
{
public $enableCsrfValidation = false;
public function actionInjection(int|string $arg, int|string $second)
{
}
}