1
0
Fork 0

Removed / check that is performed in newPath. Return Not Acceptable if a path not starting with /.

This commit is contained in:
Alexander Andreev 2023-05-28 01:29:01 +04:00
parent a0b80ced85
commit 538f1bd676
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 5 additions and 5 deletions

View File

@ -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))
}