From 0d5e5589140bec6c8a834b7f896258d62e739bfe Mon Sep 17 00:00:00 2001 From: tjpcc Date: Mon, 1 May 2023 21:42:26 -0600 Subject: fixes to /*remainder route segments --- internal/pathtree.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'internal/pathtree.go') diff --git a/internal/pathtree.go b/internal/pathtree.go index 7da4c2b..3861c8e 100644 --- a/internal/pathtree.go +++ b/internal/pathtree.go @@ -12,7 +12,7 @@ type PathTree[V any] struct { func (pt PathTree[V]) Match(path string) (*V, map[string]string) { path = strings.TrimPrefix(path, "/") - if path == "" { + if path == "" && pt.root != nil { return pt.root, map[string]string{} } m := pt.tree.Match(strings.Split(path, "/"), nil) @@ -143,9 +143,13 @@ type remainderNode[V any] struct { } func (rn remainderNode[V]) Match(segments []string, m *match[V]) *match[V] { + length := 0 + if m != nil { + length = m.length + } m = &match[V]{ value: &rn.value, - length: m.length, + length: length, prev: m, } if rn.param != "" { -- cgit v1.2.3