From 2f43f2d9343d0fd2c243dabf658ccf27fd2794da Mon Sep 17 00:00:00 2001 From: Tyler Date: Sat, 2 Apr 2022 01:21:42 -0400 Subject: [PATCH] Strip leading slashes from requests to download map --- http.go | 8 +------- map.go | 3 ++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/http.go b/http.go index b9db356..21391f9 100644 --- a/http.go +++ b/http.go @@ -112,13 +112,7 @@ func redirectHandler(w http.ResponseWriter, r *http.Request) { redirectPath := path.Join(server.Path, r.URL.Path) if dlMap != nil { - p := r.URL.Path - - if p[0] != '/' { - p = "/" + p - } - - if newPath, exists := dlMap[p]; exists { + if newPath, exists := dlMap[strings.TrimLeft(r.URL.Path, "/")]; exists { downloadsMapped.Inc() redirectPath = path.Join(server.Path, newPath) } diff --git a/map.go b/map.go index da20398..f6019f9 100644 --- a/map.go +++ b/map.go @@ -4,6 +4,7 @@ import ( "encoding/csv" "io" "os" + "strings" ) func loadMap(file string) (map[string]string, error) { @@ -32,7 +33,7 @@ func loadMap(file string) (map[string]string, error) { return nil, err } - m[row[0]] = row[1] + m[strings.TrimLeft(row[0], "/")] = strings.TrimLeft(row[1], "/") } return m, nil