Initial commit (code only without large binaries)
This commit is contained in:
27
EdgeNode/internal/utils/path.go
Normal file
27
EdgeNode/internal/utils/path.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
// CleanPath 清理Path中的多余的字符
|
||||
func CleanPath(path string) string {
|
||||
l := len(path)
|
||||
if l == 0 {
|
||||
return "/"
|
||||
}
|
||||
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
|
||||
result = append(result, '/')
|
||||
}
|
||||
} else {
|
||||
isSlash = false
|
||||
result = append(result, path[i])
|
||||
}
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
Reference in New Issue
Block a user