codeigniter4 / codeigniter4/CodeIgniter4

Missing argument in route when using `url_to` or `route_to` with regex routes

Aperta
#9,250 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
PHP
Stelle
6k
Fork
2k
Merge medio
1g 11h
PR unite (30g)
73

Descrizione

### 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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.