codeigniter4 / codeigniter4/CodeIgniter4
Missing argument in route when using `url_to` or `route_to` with regex routes
- 主要語言
- PHP
- 星號
- 6k
- 分支
- 2k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 73
描述
### PHP Version
8.3
### CodeIgniter4 Version
CodeIgniter 4.5.5
### CodeIgniter4 Installation Method
Composer (using `codeigniter4/appstarter`)
### Which operating systems have you tested for this bug?
Debian 12
### Which server did you use?
fpm-fcgi
### Database
N/A
### What happened?
The following route definition works fine as long as you don't use `url_to` or `route_to` to refer to it:
```php
$routes->get('/test(/(:any))?', 'Test::direct/$1', ['as' => 'test']);
```
Linking as below works:
```html
No parameter
1 parameter
2 parameters
```
But using both `url_to` or `route_to` fails:
```php
No parameter
1 parameter
2 parameters
```
### Steps to Reproduce
1. Add the new routes in `Routes.php`:
```php
$routes->get('/test(/(:any))?', 'Test::direct/$1', ['as' => 'test']);
$routes->get('/test_urlto(/(:any))?', 'Test::urlto/$1', ['as' => 'urlto']);
$routes->get('/test_routeto(/(:any))?', 'Test::routeto/$1', ['as' => 'routeto']);
```
2. Create the `Test` controller:
```php
$params]);
}
public function urlto(...$params): string
{
return view('test_urlto', ['params' => $params]);
}
public function routeto(...$params): string
{
return view('test_routeto', ['params' => $params]);
}
}
```
3. Create the respective views:
A) direct view
```html
Test
Testing CI4 Routing with Parameters
Test using string directly
Passed Parameters
```
B) view using `url_to`
```html
Test
Testing CI4 Routing with Parameters
Test using url_to
Passed Parameters
```
4. Access those views at: /test and /test_urlto
### Expected Output
No `InvalidArgumentException`, `Missing argument for "(/(:any)" in route "test_urlto(/(:any))?"` while using both `url_to` and `route_to` .
### Anything else?
- One can try it with `public bool $multipleSegmentsOneParam = true;` or `public bool $multipleSegmentsOneParam = false;` in `Routing.php`. The error is the same in both situations (just the parameters are treated differently, as expected).
- One can also use a regex like `'(/(.+))?'` instead of `(/(:any))? `. The error remains.
貢獻指南
研究方向
Reproduce the failure using the routes in Routes.php and compare url_to and route_to with both Routing.php multipleSegmentsOneParam settings. Start by tracing route parameter handling from the named regex routes; done means all shown links generate without InvalidArgumentException and preserve the expected parameters.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- php
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 48/100