From ac33339689e5d8a875d37e23eebab0175c6ff214 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 24 Nov 2021 15:01:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=88=E5=B9=B6URL?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=BD=99=E5=88=86=E9=9A=94=E7=AC=A6=E6=97=B6?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=8F=82=E6=95=B0=E5=8F=91=E7=94=9F=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/utils/path.go | 5 ++++- internal/utils/path_test.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/utils/path.go b/internal/utils/path.go index c17a7bc..5fffef9 100644 --- a/internal/utils/path.go +++ b/internal/utils/path.go @@ -9,6 +9,10 @@ func CleanPath(path string) string { result := []byte{'/'} isSlash := true for i := 0; i < l; i++ { + if path[i] == '?' { + result = append(result, path[i:]...) + break + } if path[i] == '\\' || path[i] == '/' { if !isSlash { isSlash = true @@ -21,4 +25,3 @@ func CleanPath(path string) string { } return string(result) } - diff --git a/internal/utils/path_test.go b/internal/utils/path_test.go index 6b6b8a5..f3fd35c 100644 --- a/internal/utils/path_test.go +++ b/internal/utils/path_test.go @@ -16,6 +16,11 @@ func TestCleanPath(t *testing.T) { a.IsTrue(CleanPath("/hello////world") == "/hello/world") } +func TestCleanPath_Args(t *testing.T) { + a := assert.NewAssertion(t) + a.IsTrue(CleanPath("/hello/world?base=///////") == "/hello/world?base=///////") +} + func BenchmarkCleanPath(b *testing.B) { for i := 0; i < b.N; i++ { _ = CleanPath("/hello///world/very/long/very//long")