Skip to content

Route caching returns wrong route if route name is equal to the application prefix #42539

@ndossche

Description

@ndossche
  • Laravel Version: 9.14.0
  • PHP Version: 8.1.6
  • Database Driver & Version: MariaDB 10.8.3

Description:

While upgrading a Laravel application from 6.x to 9.x, I encountered the following regression.

Context: We have a Laravel application installed on the path http://server/pathname/.
We have a route linked to a controller in our application with the same name as the prefix path of the application: "/pathname" (i.e. accessible via http://server/pathname/pathname).

The bug: The application works fine in 9.x unless I enable route caching. When I surf to the homepage (http://server/pathname/) with route caching enabled, Laravel believes I'm actually surfing to http://server/pathname/pathname. This did work perfectly fine in Laravel 6.x with route caching enabled.

I tracked it down to the function match in the class CompiledRouteCollection. The wrong route is returned from the matchRequest call. I manually worked around this issue by modifying requestWithoutTrailingSlash to also remove the prefix "/pathname".

Steps To Reproduce:

  • Create a new Laravel 9.x app under a subdirectory "/pathname" (perhaps a directory is not strictly necessary, I believe any kind of prefix will do)
  • Create a route linked to a controller with path "/pathname"
  • Execute route:cache
  • The application returns the page for "/pathname/pathname" when surfing to "/pathname"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions