Skip to content

fix wildcard routes being skipped by fast path method lookup closes #693#694

Open
KnifeLemon wants to merge 1 commit intoflightphp:masterfrom
KnifeLemon:master
Open

fix wildcard routes being skipped by fast path method lookup closes #693#694
KnifeLemon wants to merge 1 commit intoflightphp:masterfrom
KnifeLemon:master

Conversation

@KnifeLemon
Copy link
Copy Markdown
Contributor

Fixes the route registration order regression introduced in v3.17.1 by the method-specific fast path added in #658.

closes #693

Fix

Store routes in routesByMethod using their global index in $routes as the array key. When building the fast path candidates, merge the two buckets and ksort by key to restore registration order.

// map() — use global route index as key
$this->routesByMethod[$method][count($this->routes) - 1] = $route;

// route() — merge and sort by registration order
$candidates = ($this->routesByMethod[$requestMethod] ?? []) + ($this->routesByMethod['*'] ?? []);
ksort($candidates);

Now the merged candidates are always in registration order regardless of method, and the fast path performance benefit (only URL-matching against eligible routes) is preserved.

Testing

Added regression test testWildcardPassthroughRouteBeforeSpecificGetRoute in RouterTest.

> phpunit --filter RouterTest
PHPUnit 9.6.34 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.29
Configuration: C:\FlightPHP\core\phpunit.xml.dist
Random Seed:   1776965395

................................................................. 65 / 66 ( 98%)
.                                                                 66 / 66 (100%)

Time: 00:00.031, Memory: 8.00 MB

OK (66 tests, 87 assertions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Method-specific route matching in v3.17.1 affects the order

1 participant