diff --git a/src/think/route/Url.php b/src/think/route/Url.php index f2388a090d..a9fad24a57 100644 --- a/src/think/route/Url.php +++ b/src/think/route/Url.php @@ -224,6 +224,11 @@ protected function parseUrl(string $url, string | bool &$domain): string } } + $ext = pathinfo($url, PATHINFO_EXTENSION); + if ('' !== $ext && str_ends_with($url, '.' . $ext)) { + $url = substr($url, 0, -strlen($ext) - 1); + } + return $url; } diff --git a/tests/UrlRouteTest.php b/tests/UrlRouteTest.php index a994ef0781..c4d4f0ee77 100644 --- a/tests/UrlRouteTest.php +++ b/tests/UrlRouteTest.php @@ -41,6 +41,21 @@ public function testUrlDispatch() $this->assertEquals('bar', $response->getContent()); } + /** + * 测试 Route::buildUrl() + */ + public function testBuild() + { + $request = $this->makeRequest('index/index.html'); + + $this->app->request = $request; + + $urlBuild = new \think\route\Url($this->route, $this->app, '', []); + $result = $urlBuild->build(); + + $this->assertEquals('/index/index.html', $result); + } + /** * @param $path * @param string $method