Handle special chars in exercice path

This commit is contained in:
nemunaire 2022-05-24 17:36:33 +02:00
commit 45a9240834
2 changed files with 6 additions and 3 deletions

View file

@ -3,13 +3,15 @@ package main
import (
"log"
"net/http"
"net/url"
"path"
"strings"
"text/template"
)
var enableResolutionRoute bool = false
type ResolutionHandler struct {}
type ResolutionHandler struct{}
const resolutiontpl = `<!DOCTYPE html>
<html>
@ -40,7 +42,7 @@ func (s ResolutionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if resolutionTmpl, err := template.New("resolution").Parse(resolutiontpl); err != nil {
log.Println("Cannot create template: ", err)
} else if err = resolutionTmpl.Execute(w, path.Join("/vids/", r.URL.Path)); err != nil {
} else if err = resolutionTmpl.Execute(w, path.Join("/vids/", strings.Replace(url.PathEscape(r.URL.Path), "%2F", "/", -1))); err != nil {
log.Println("An error occurs during template execution: ", err)
}
}