summaryrefslogtreecommitdiffstats
path: root/common/paths/url.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/paths/url.go')
-rw-r--r--common/paths/url.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/common/paths/url.go b/common/paths/url.go
index 193b0cd0e..c538d8f2c 100644
--- a/common/paths/url.go
+++ b/common/paths/url.go
@@ -17,6 +17,7 @@ import (
"fmt"
"net/url"
"path"
+ "path/filepath"
"strings"
)
@@ -152,3 +153,29 @@ func Uglify(in string) string {
// /section/name.html -> /section/name.html
return path.Clean(in)
}
+
+// UrlToFilename converts the URL s to a filename.
+// If ParseRequestURI fails, the input is just converted to OS specific slashes and returned.
+func UrlToFilename(s string) (string, bool) {
+ u, err := url.ParseRequestURI(s)
+
+ if err != nil {
+ return filepath.FromSlash(s), false
+ }
+
+ p := u.Path
+
+ if p == "" {
+ p, _ = url.QueryUnescape(u.Opaque)
+ return filepath.FromSlash(p), true
+ }
+
+ p = filepath.FromSlash(p)
+
+ if u.Host != "" {
+ // C:\data\file.txt
+ p = strings.ToUpper(u.Host) + ":" + p
+ }
+
+ return p, true
+}