mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 22:32:40 +08:00
Fix #18859: Fix yii\web\Controller::bindInjectedParams() to not throw error when argument of ReflectionUnionType type is passed
This commit is contained in:
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
|||||||
2.0.49 under development
|
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)
|
- Enh #19841: Allow jQuery 3.7 to be installed (wouter90)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -141,6 +141,7 @@ class Controller extends \yii\base\Controller
|
|||||||
} elseif (
|
} elseif (
|
||||||
PHP_VERSION_ID >= 70000
|
PHP_VERSION_ID >= 70000
|
||||||
&& ($type = $param->getType()) !== null
|
&& ($type = $param->getType()) !== null
|
||||||
|
&& method_exists($type, 'isBuiltin')
|
||||||
&& $type->isBuiltin()
|
&& $type->isBuiltin()
|
||||||
&& ($params[$name] !== null || !$type->allowsNull())
|
&& ($params[$name] !== null || !$type->allowsNull())
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -10,7 +10,6 @@ namespace yiiunit\framework\web;
|
|||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\base\InlineAction;
|
use yii\base\InlineAction;
|
||||||
use yii\web\HttpException;
|
|
||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\web\Response;
|
use yii\web\Response;
|
||||||
use yii\web\ServerErrorHttpException;
|
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', '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');
|
$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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
tests/framework/web/FakePhp80Controller.php
Normal file
20
tests/framework/web/FakePhp80Controller.php
Normal 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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user