-
Laravel Version11.39.1 PHP Version8.3.16 Database Driver & Versionsqlite DescriptionVisiting the path This does not only apply to the fallback route but also to wildcard routes. Route::get('/{path}', fn() => 'Test Wildcard')->where('path', '.*');
Route::fallback(fn() => 'Test Fallback'); Originally discovered in statamic: statamic/cms#11387 Steps To Reproduce
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 3 replies
-
Looks like it is a special character that can't be parsed by PHP. |
Beta Was this translation helpful? Give feedback.
-
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? |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
@Jubeki not exactly true. And from the PHP.net documentation comment itself: |
Beta Was this translation helpful? Give feedback.
-
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.) |
Beta Was this translation helpful? Give feedback.
-
I'm agree more to this response here and invalid charater should return 400 (Bad Request) https://stackoverflow.com/a/33005652 |
Beta Was this translation helpful? Give feedback.
-
You can handle a default route also in \App\Exceptions\Handler::render
|
Beta Was this translation helpful? Give feedback.
I'm agree more to this response here and invalid charater should return 400 (Bad Request) https://stackoverflow.com/a/33005652