From 01ef0d51837a20f56a0ded5addf813e94b023306 Mon Sep 17 00:00:00 2001 From: cdramey Date: Sat, 24 Nov 2018 04:22:41 +0000 Subject: [PATCH] Fixed bad URL redirect bug --- pages/root.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pages/root.go b/pages/root.go index e3e82aa..e786dae 100644 --- a/pages/root.go +++ b/pages/root.go @@ -47,6 +47,7 @@ func (ctx *RootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { id, err := qurl.FromString(fname[1:len(fname)]) if err != nil { http.Redirect(w, r, "/", http.StatusTemporaryRedirect) + return } q, err := ctx.Storage.GetQURLByID(id) @@ -56,6 +57,11 @@ func (ctx *RootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + if q == nil { + http.Redirect(w, r, "/", http.StatusTemporaryRedirect) + return + } + http.Redirect(w, r, q.URL, http.StatusPermanentRedirect) } }