diff --git a/cmd/files.go b/cmd/files.go index 6006ef2..a5173c0 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -77,6 +77,13 @@ func (p *Path) Decrement() { p.Number = p.Number - 1 } +func preparePath(path string) string { + path = filepath.Clean(path) + path = filepath.ToSlash(path) + + return path +} + func appendPath(directory, path string, files *Files, stats *Stats) { files.Mutex.Lock() files.List[directory] = append(files.List[directory], path) diff --git a/cmd/version.go b/cmd/version.go index cdc605d..5b632b5 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.17.4" +var Version = "0.18.0" func init() { rootCmd.AddCommand(versionCmd) diff --git a/cmd/web.go b/cmd/web.go index 59803c5..81b34ce 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -110,7 +110,7 @@ func stripQueryParams(inUrl string) (string, error) { url.RawQuery = "" - return url.String(), nil + return strings.TrimPrefix(url.String(), "/"), nil } func refererToUri(referer string) string { @@ -155,7 +155,7 @@ func serveHtml(w http.ResponseWriter, r *http.Request, filePath string) error { default: htmlBody += ` ` @@ -289,7 +289,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { newUrl := fmt.Sprintf("%v%v%v", r.URL.Host, - filePath, + url.PathEscape(filepath.Clean(filePath)), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) @@ -315,7 +315,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { newUrl := fmt.Sprintf("%v%v%v", r.URL.Host, - filePath, + url.PathEscape(filepath.Clean(filePath)), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) @@ -359,7 +359,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { newUrl := fmt.Sprintf("%v%v%v", r.URL.Host, - filePath, + url.PathEscape(filepath.Clean(filePath)), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) @@ -385,7 +385,7 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { newUrl := fmt.Sprintf("%v%v%v", r.URL.Host, - filePath, + url.PathEscape(filepath.Clean(filePath)), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) @@ -399,14 +399,14 @@ func serveHtmlHandler(paths []string, re regexp.Regexp) appHandler { return err } - newUrl := fmt.Sprintf("%v%v%v", - r.URL.Host, - filePath, + newUrl := fmt.Sprintf("http://%v/%v%v", + r.Host, + preparePath(filePath), generateQueryParams(&filters, sortOrder), ) http.Redirect(w, r, newUrl, RedirectStatusCode) default: - filePath := r.URL.Path + filePath := strings.TrimPrefix(r.URL.Path, "/") exists, err := fileExists(filePath) if err != nil { @@ -453,8 +453,8 @@ func ServePage(args []string) error { re := regexp.MustCompile(`(.+)([0-9]{3})(\..+)`) - http.Handle("/", serveHtmlHandler(paths, *re)) http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths))) + http.Handle("/", serveHtmlHandler(paths, *re)) http.HandleFunc("/favicon.ico", doNothing) err = http.ListenAndServe(":"+strconv.FormatInt(int64(Port), 10), nil) diff --git a/roulette.exe b/roulette.exe new file mode 100644 index 0000000..2510c9e Binary files /dev/null and b/roulette.exe differ