Use a portable version of addSlash

This commit is contained in:
Ben Adrian Sarmiento
2024-07-21 03:32:16 +02:00
parent d0168283c9
commit 66053ed621

View File

@@ -1,14 +1,22 @@
package dav
import (
"path/filepath"
"strings"
)
// addSlash ensures the input string ends with a slash regardless of the OS
func addSlash(input string) string {
p := filepath.Join("/", input)
if p == "/" || strings.HasSuffix(p, "/") {
return p
// Standardize the path separator to use forward slashes
input = strings.ReplaceAll(input, "\\", "/")
// 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
}