Skip to content
New issue

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

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

Already on GitHub? # to your account

preg_match errors are ignored #167

Open
Lumaraf opened this issue Jun 13, 2018 · 0 comments
Open

preg_match errors are ignored #167

Lumaraf opened this issue Jun 13, 2018 · 0 comments
Labels

Comments

@Lumaraf
Copy link

Lumaraf commented Jun 13, 2018

If routes contain complicated (and inefficient) patterns for parameters the pcre.backtrack_limit or other limits can be reached when checking for matching routes. FastRoute should check if preg_match returned false and abort routing with an error instead of silently treating this as not matching routes.

The following example shows that on PHP7 with default pcre.backtrack_limit the second route will not match on paths with more than 14 characters.

$dispatcher = \FastRoute\simpleDispatcher(function (\FastRoute\RouteCollector $r) {
    $r->addRoute(['GET'], '/{p:(?:a?a?)*}/complicated', 'complicated_pattern');
    $r->addRoute(['GET'], '/{p:a+}', 'a');
});
for ($n = 1; ; $n++) {
    $routeInfo = $dispatcher->dispatch('GET', '/' . str_repeat('a', $n));
    if ($routeInfo[0] !== \FastRoute\Dispatcher::FOUND) {
        var_dump($n, $routeInfo);
        break;
    }
}
codemasher added a commit to codemasher/FastRoute that referenced this issue Mar 12, 2019
@lcobucci lcobucci added the bug label Apr 12, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants