修复合并URL中多余分隔符时导致参数发生变化的Bug

This commit is contained in:
GoEdgeLab
2021-11-24 15:01:06 +08:00
parent aa9ce4e260
commit ac33339689
2 changed files with 9 additions and 1 deletions

View File

@@ -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)
}

View File

@@ -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")