fix(dispatcher): surface preg_match() engine failures instead of treating them as no-match
All dispatcher strategies checked preg_match() results with `!== 1`, which conflates a genuine no-match (0) with a PCRE engine failure (false), e.g. PREG_BACKTRACK_LIMIT_ERROR from a catastrophically backtracking route pattern. Because dynamic routes for the same method are combined into shared regex chunks, one such route could make the preg_match() call for the whole chunk fail, silently turning an unrelated, cheap route in that chunk into a spurious NOT_FOUND. Add a shared matchRoute() helper on RegexBasedAbstract that calls preg_match() and throws a RuntimeException (including preg_last_error_msg()) when it returns false, while preserving the existing 0/1 no-match/match behavior. Update GroupCountBased, GroupPosBased, CharCountBased and MarkBased to use it. Fixes #167
This commit is contained in:
1 parent
c0905f9089
commit
7ac8857878
6 files changed
+62
-9
No files matched your search
@@ -7,7 +7,6 @@ use FastRoute\Dispatcher\Result\Matched;
|
||||
|
||||
use function assert;
|
||||
use function end;
|
||||
use function preg_match;
|
||||
|
||||
/** @final */
|
||||
class CharCountBased extends RegexBasedAbstract
|
||||
@@ -18,7 +17,7 @@ class CharCountBased extends RegexBasedAbstract
|
||||
foreach ($routeData as $data) {
|
||||
assert(isset($data['suffix']));
|
||||
|
||||
if (preg_match($data['regex'], $uri . $data['suffix'], $matches) !== 1) {
|
||||
if ($this->matchRoute($data['regex'], $uri . $data['suffix'], $matches) !== 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user