mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-09 03:50:27 +08:00
修复合并URL中多余分隔符时导致参数发生变化的Bug
This commit is contained in:
@@ -9,6 +9,10 @@ func CleanPath(path string) string {
|
|||||||
result := []byte{'/'}
|
result := []byte{'/'}
|
||||||
isSlash := true
|
isSlash := true
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
|
if path[i] == '?' {
|
||||||
|
result = append(result, path[i:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
if path[i] == '\\' || path[i] == '/' {
|
if path[i] == '\\' || path[i] == '/' {
|
||||||
if !isSlash {
|
if !isSlash {
|
||||||
isSlash = true
|
isSlash = true
|
||||||
@@ -21,4 +25,3 @@ func CleanPath(path string) string {
|
|||||||
}
|
}
|
||||||
return string(result)
|
return string(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ func TestCleanPath(t *testing.T) {
|
|||||||
a.IsTrue(CleanPath("/hello////world") == "/hello/world")
|
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) {
|
func BenchmarkCleanPath(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_ = CleanPath("/hello///world/very/long/very//long")
|
_ = CleanPath("/hello///world/very/long/very//long")
|
||||||
|
|||||||
Reference in New Issue
Block a user