1 回答

TA貢獻1871條經驗 獲得超13個贊
需要明確的是,這不是一個錯誤。錯誤意味著這是框架開發人員明確表示不應該發生但實際上發生的事情。這主要是一種未定義的行為。
發生這種情況的原因是請求如何確定當前路徑:
在Request::path()
public function path()
{
? ? $pattern = trim($this->getPathInfo(), '/');
? ? return $pattern == '' ? '/' : $pattern;
}
這將從/
當前路徑信息中修剪以獲取路徑。這并不是一件不合理的事情,因為您通常不需要前導和尾隨斜杠,但這會導致具有許多前導和尾隨斜杠的路徑也可以像 https://laravel.com////docs 一樣工作/5.5/errors/////#http-exceptions
發生這種情況的原因是因為返回的標準路由驗證器Route::getValidators()
(特別是使用的 UriValidator?$request->path()
)
如果你真的必須堅持“修復”這個問題,那么你可以添加一個自定義驗證器來檢查這個確切的事情:
class MyUriValidator implements ValidatorInterface? {
? ? public function matches(Route $route, Request $request)
? ? {
? ? ? ? $path = $request->getPathInfo();
? ? ? ? return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
? ? }
}
然后您可以在您的中注冊這個額外的驗證器AppServiceProvider:
public function boot() {
? ? Route::$validators = array_merge(Route::getValidators(), [ new MyUriValidator ]);
}
- 1 回答
- 0 關注
- 151 瀏覽
添加回答
舉報