From 4b3d1e93529ce7268f9cd6e27c155a3eede5d429 Mon Sep 17 00:00:00 2001 From: jwj Date: Tue, 3 Mar 2026 23:52:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20url=20=E7=94=9F=E6=88=90?= =?UTF-8?q?=E3=80=82=20=E4=BF=AE=E6=AD=A3=20PATH=5FINFO=20=E6=90=BA?= =?UTF-8?q?=E5=B8=A6=E5=90=8E=E7=BC=80=E6=97=B6=EF=BC=8Curl()=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=9A=84=E5=9C=B0=E5=9D=80=E4=BC=9A=E5=86=8D=E6=AC=A1?= =?UTF-8?q?=E5=8F=A0=E5=8A=A0=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/think/route/Url.php | 5 +++++ tests/UrlRouteTest.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+) 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