Use a portable version of addSlash
This commit is contained in:
@@ -1,14 +1,22 @@
|
|||||||
package dav
|
package dav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// addSlash ensures the input string ends with a slash regardless of the OS
|
||||||
func addSlash(input string) string {
|
func addSlash(input string) string {
|
||||||
p := filepath.Join("/", input)
|
// Standardize the path separator to use forward slashes
|
||||||
if p == "/" || strings.HasSuffix(p, "/") {
|
input = strings.ReplaceAll(input, "\\", "/")
|
||||||
return p
|
|
||||||
|
// Ensure the input starts with a slash
|
||||||
|
if !strings.HasPrefix(input, "/") {
|
||||||
|
input = "/" + input
|
||||||
}
|
}
|
||||||
return p + "/"
|
|
||||||
|
// Ensure the path ends with a slash
|
||||||
|
if !strings.HasSuffix(input, "/") {
|
||||||
|
input += "/"
|
||||||
|
}
|
||||||
|
return input
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user