Skip to content

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

@dimtrovich

Description

@dimtrovich

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions