From ad99bf180197e0e6d82231a86457585de16366a8 Mon Sep 17 00:00:00 2001 From: Xabi Date: Fri, 2 Oct 2020 15:09:03 +0200 Subject: [PATCH] fix: fix panic when accessing nonexistent .js file in static path (#1105) --- http/static.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/http/static.go b/http/static.go index ab203b8c..d34302cf 100644 --- a/http/static.go +++ b/http/static.go @@ -79,7 +79,14 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, box * data["Json"] = string(b) - index := template.Must(template.New("index").Delims("[{[", "]}]").Parse(box.MustString(file))) + fileContents, err := box.String(file) + if err != nil { + if err == os.ErrNotExist { + return http.StatusNotFound, err + } + return http.StatusInternalServerError, err + } + index := template.Must(template.New("index").Delims("[{[", "]}]").Parse(fileContents)) err = index.Execute(w, data) if err != nil { return http.StatusInternalServerError, err