From 538f1bd676143841dd059c432bbe46ea36b92a00 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 28 May 2023 01:29:01 +0400 Subject: [PATCH] Removed / check that is performed in newPath. Return Not Acceptable if a path not starting with /. --- httpr.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/httpr.go b/httpr.go index e9b995d..a67e232 100644 --- a/httpr.go +++ b/httpr.go @@ -133,13 +133,13 @@ func New() *Router { func (rr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) { if tree, ok := rr.tree[r.Method]; ok { - if r.URL.Path[0] != '/' { - panic("first element of path should be a slash (/) symbol") + path, err := newPath(r.URL.Path) + if err != nil { + http.Error(w, err.Error(), http.StatusNotAcceptable) + return } - path, _ := newPath(r.URL.Path) - - if handler, params := tree.get(path, 0); handler != nil { + if handler, params := tree.get(path); handler != nil { if params != nil { r = r.WithContext(context.WithValue(r.Context(), ParamsKey, params)) }