Files
zurg/pkg/dav/util.go
2024-01-20 14:51:16 +01:00

26 lines
854 B
Go

package dav
import (
"net/url"
"strings"
)
func customPathEscape(input string) string {
// First, URL-escape the path segments
segments := strings.Split(input, "/")
for i, segment := range segments {
escapedSegment := strings.ReplaceAll(segment, "%", "ZURG25")
escapedSegment = url.PathEscape(escapedSegment)
escapedSegment = strings.ReplaceAll(escapedSegment, "ZURG25", "%25")
segments[i] = escapedSegment
}
escapedPath := strings.Join(segments, "/")
// Convert any XML-escaped sequences back to URL-escaped sequences
escapedPath = strings.ReplaceAll(escapedPath, "$", "%24")
escapedPath = strings.ReplaceAll(escapedPath, "&", "%26")
escapedPath = strings.ReplaceAll(escapedPath, "+", "%2B")
escapedPath = strings.ReplaceAll(escapedPath, ":", "%3A")
escapedPath = strings.ReplaceAll(escapedPath, "@", "%40")
return escapedPath
}