-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback Route gets ignored #54338
Comments
Looks like it is a special character that can't be parsed by PHP. |
We use a fallback route for that purpose. If it is unable to parse, it should still show the fallback route. This makes more sense, I think. Can I contribute? |
@crynobone It can be parsed, it is just an invisible character (which probably will be trimmed if that happens somewhere)
@iam-subho You can contribute if you want. The Laravel Framework is open-source. I will also take a further look the upcoming days, if something can be improved in the framework. |
@Jubeki not exactly true. And from the PHP.net documentation comment itself: |
Okay, you are right, I didn't consider this enough. I simply looked at the result of the Link you have given and there the length of the string was printed as 1, therefor I assumed it is an invisible character. I at least know what the Problem is. The fallback route, also gets registered with the wildcard Because the code in Here some debugging information. I added some dump statements to the UriValidator, so that I can take a look at what the values of the variables are. <?php
namespace Illuminate\Routing\Matching;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
class UriValidator implements ValidatorInterface
{
/**
* Validate a given rule against a route and request.
*
* @param \Illuminate\Routing\Route $route
* @param \Illuminate\Http\Request $request
* @return bool
*/
public function matches(Route $route, Request $request)
{
$path = rtrim($request->getPathInfo(), '/') ?: '/';
if ($route->isFallback) {
dump($route->getCompiled()->getRegex());
dump(rawurldecode($path));
dd($path);
}
return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
}
} This is the result: // $route->getCompiled()->getRegex()
"{^/(?P<fallbackPlaceholder>.*)$}sDu"
// rawurldecode($path)
b"/À"
// $path
"/%C0" You can also clearly see that If we were to make changes to the behaviour, I think this should go to Laravel 12, because I am not sure how much of an impact this change has. In my opinion something should be changed, because currently the URL is broken, how about return a Or the fallback behaviour somehow needs to be adjusted, to also be called on invalid / malformed urls. Because currently If you use the fallback method or a wildcard route to render the 404 page with some additional variables, these will not be available. (Of course you could load these variables inside the 404.blade.php file instead of using the fallback route, but it still unexpected that the fallback route does not get called.) |
Laravel Version
11.39.1
PHP Version
8.3.16
Database Driver & Version
sqlite
Description
Visiting the path
/%c0
on a fresh laravel application results in the fallback route being ignored and the default 404 page will instead be displayed.This does not only apply to the fallback route but also to wildcard routes.
Originally discovered in statamic: statamic/cms#11387
Steps To Reproduce
Route::fallback(fn() => 'Test');
Test
, meaning the fallback route gets registered)The text was updated successfully, but these errors were encountered: