Escape URL

This commit is contained in:
Christoph Polcin
2018-05-23 13:41:06 +02:00
parent c49c91989e
commit 375f391c8a
4 changed files with 54 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/xml"
"fmt"
"io"
"net/url"
"os"
"strconv"
"strings"
@@ -31,6 +32,15 @@ func newPathErrorErr(op string, path string, err error) error {
}
}
// PathEscape escapes all segemnts of a given path
func PathEscape(path string) string {
s := strings.Split(path, "/")
for i, e := range s {
s[i] = url.PathEscape(e)
}
return strings.Join(s, "/")
}
// FixSlash appends a trailing / to our string
func FixSlash(s string) string {
if !strings.HasSuffix(s, "/") {