From 66053ed621e8e7b4b5f3876cde5adc03f28f484d Mon Sep 17 00:00:00 2001 From: Ben Adrian Sarmiento Date: Sun, 21 Jul 2024 03:32:16 +0200 Subject: [PATCH] Use a portable version of addSlash --- internal/dav/util.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/dav/util.go b/internal/dav/util.go index 6e2bdda..b192bc3 100644 --- a/internal/dav/util.go +++ b/internal/dav/util.go @@ -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 }