1
0
Fork 0
mirror of https://github.com/Luzifer/badge-gen.git synced 2024-12-20 16:41:16 +00:00

[#1] Allow URI encoded slash in badge fields

Fixes `/static/test/branch%2Fname` to result in `[ test | branch ]` badge

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-03-11 10:37:39 +01:00
parent 499355a617
commit 53f2261a84
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

10
app.go
View file

@ -115,7 +115,7 @@ func main() {
log.Printf("Loaded %d value pairs into configuration store", len(configStore)) 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("/v1/badge", generateBadge).Methods("GET")
r.HandleFunc("/{service}/{parameters:.*}", generateServiceBadge).Methods("GET") r.HandleFunc("/{service}/{parameters:.*}", generateServiceBadge).Methods("GET")
r.HandleFunc("/", handleDemoPage) r.HandleFunc("/", handleDemoPage)
@ -126,7 +126,15 @@ func main() {
func generateServiceBadge(res http.ResponseWriter, r *http.Request) { func generateServiceBadge(res http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
service := vars["service"] service := vars["service"]
var err error
params := strings.Split(vars["parameters"], "/") 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) al := accessLogger.New(res)