From 53f2261a840ac431321121fdebe213bfd608e144 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 11 Mar 2021 10:37:39 +0100 Subject: [PATCH] [#1] Allow URI encoded slash in badge fields Fixes `/static/test/branch%2Fname` to result in `[ test | branch ]` badge Signed-off-by: Knut Ahlers --- app.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index 6decc54..f3c7b1b 100644 --- a/app.go +++ b/app.go @@ -115,7 +115,7 @@ func main() { log.Printf("Loaded %d value pairs into configuration store", len(configStore)) } - r := mux.NewRouter() + r := mux.NewRouter().UseEncodedPath() r.HandleFunc("/v1/badge", generateBadge).Methods("GET") r.HandleFunc("/{service}/{parameters:.*}", generateServiceBadge).Methods("GET") r.HandleFunc("/", handleDemoPage) @@ -126,7 +126,15 @@ func main() { func generateServiceBadge(res http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) service := vars["service"] + + var err error params := strings.Split(vars["parameters"], "/") + for i := range params { + if params[i], err = url.QueryUnescape(params[i]); err != nil { + http.Error(res, "Invalid escaping in URL", http.StatusBadRequest) + return + } + } al := accessLogger.New(res)