Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Reverse routing causes error "preg_match(): Compilation failed: missing closing parenthesis" #7876

Closed
dimtrovich opened this issue Aug 29, 2023 · 5 comments · Fixed by #7880
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@dimtrovich
Copy link

dimtrovich commented Aug 29, 2023

PHP Version

8.1

CodeIgniter4 Version

4.4.0

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli-server (PHP built-in webserver)

Database

No response

What happened?

Unable to generate a URL attached to a route defined with custom placeholders.
An exception is thrown at SYSTEMPATH\Router\RouteCollection.php at line 1343

Steps to Reproduce

  • Add custom placeholder
$routes->addPlaceholder([
    'version' => 'master|\d+\.(?:\d+|x)',
    'page'    => '[a-z0-9-]+',
]);
  • Create 2 routes for test
$routes->get('docs/(:version)', function() {
    echo 'Test the documentation';
});
$routes->get('docs/(:version)/(:page)', function() {
    echo 'Test the documentation segment';
}, ['as' => 'docs.version']);
  • So far everything is ok. Now let's try to get a 2nd route url (docs.version) from the 1st route
$routes->get('docs/(:version)', function() {
    echo 'Test the documentation --- '  . url_to('docs.version', '10.9', 'install');
});

at this level it no longer gives. yet if I don't use the url_to function, the text displays normally, so I dare to believe that my regex has no error

1st Image: Error when i use url_to function in the 1st route
2nd Image: The 2nd route is displayed normally
3th Image: The 1st route is displayed normally when the url_to function is not used

Error when i use url_to  function
the 2nd route is displayed normally
the 1st route is displayed normally when the url_to function is not used

Expected Output

the display of the corresponding url (http://localhost:8000/docs/10.9/install)

Anything else?

This bug is a continuation of a ticket (feature request) opened on the forum: https://forum.codeigniter.com/showthread.php?tid=88365

@dimtrovich dimtrovich added the bug Verified issues on the current code behavior or pull requests that will fix them label Aug 29, 2023
@neznaika0
Copy link
Contributor

Try up route as?

version/page 
version/

@kenjis
Copy link
Member

kenjis commented Aug 29, 2023

Thank you for reporting.

This is duplicate of #7237
If you could fix the code, send a PR.

@kenjis kenjis closed this as completed Aug 29, 2023
@kenjis
Copy link
Member

kenjis commented Aug 29, 2023

The cause seems to be the same, but the error occurs in a different place, so reopen.

@kenjis kenjis reopened this Aug 29, 2023
@kenjis
Copy link
Member

kenjis commented Aug 29, 2023

$ php spark routes

CodeIgniter v4.4.0 Command Line Tool - Server Time: 2023-08-29 21:25:57 UTC+00:00

+--------+-------------------------------------------+--------------+------------------------------+----------------+---------------+
| Method | Route                                     | Name         | Handler                      | Before Filters | After Filters |
+--------+-------------------------------------------+--------------+------------------------------+----------------+---------------+
| GET    | /                                         | »            | \App\Controllers\Home::index |                | toolbar       |
| GET    | docs/(master|\d+\.(?:\d+|x))              | »            | (Closure)                    | <unknown>      | <unknown>     |
| GET    | docs/(master|\d+\.(?:\d+|x))/([a-z0-9-]+) | docs.version | (Closure)                    | <unknown>      | <unknown>     |
+--------+-------------------------------------------+--------------+------------------------------+----------------+---------------+

@kenjis kenjis changed the title Bug: reverseRoute -- preg_match(): Compilation failed: missing closing parenthesis Bug: Reverse routing causes error "preg_match(): Compilation failed: missing closing parenthesis" Aug 29, 2023
@kenjis
Copy link
Member

kenjis commented Aug 30, 2023

Try #7880

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants