From e1d21a73cf1a9e1e14c3770f1daf57e6914c90bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Adamski?= Date: Fri, 1 Mar 2019 08:27:11 +0100 Subject: [PATCH] tests and fix for findChildByKind executed on nil node --- router.go | 3 +++ router_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/router.go b/router.go index 73f0b68b..aae99a37 100644 --- a/router.go +++ b/router.go @@ -218,6 +218,9 @@ func (n *node) findChildWithLabel(l byte) *node { } func (n *node) findChildByKind(t kind) *node { + if n == nil { + return nil + } for _, c := range n.children { if c.kind == t { return c diff --git a/router_test.go b/router_test.go index a5d53c0a..f084fb98 100644 --- a/router_test.go +++ b/router_test.go @@ -756,6 +756,12 @@ func TestRouterPriorityNotFound(t *testing.T) { c.Set("b", 2) return nil }) + r.Add(http.MethodGet, "/:lang/", func(c Context) error { + return nil + }) + r.Add(http.MethodGet, "/:lang/dupa", func(c Context) error { + return nil + }) // Find r.Find(http.MethodGet, "/a/foo", c)