diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-05-15 11:40:34 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-05-15 20:25:25 +0200 |
commit | fc9f315d86e1fe51c3d1eec3b60680113b2e3aa6 (patch) | |
tree | 69e8ffc4d84e8f02e0e6f098c27cda9dd3bcc544 /common/paths | |
parent | 4b189d8fd93d3fa326b31d451d5594c917e6c714 (diff) |
Improve SASS errors
Fixes #9897
Diffstat (limited to 'common/paths')
-rw-r--r-- | common/paths/url.go | 27 |
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 +} |