From 28aec211e1e40459c1773ca5a97843990e7824f4 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 6 Jan 2026 07:00:25 +0000 Subject: [PATCH] Refactor wildcard matching logic in TrieRouter Replaced manual string reconstruction hack in CatchAll logic with a cleaner approach using `currentPath` capture. This simplifies the code and avoids potential edge cases with path separators. --- routers/trie.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/routers/trie.go b/routers/trie.go index dfdfbf2..ed6d1c7 100644 --- a/routers/trie.go +++ b/routers/trie.go @@ -163,6 +163,9 @@ func (r *TrieRouter) Find(method, path string, ctx *amaro.Context) (*amaro.Route // Zero-allocation iteration for len(searchPath) > 0 || n != nil { + // Capture the current path state before slicing, to use in CatchAll + currentPath := searchPath + if len(searchPath) == 0 { if n.Handler != nil { return &n.Route, nil @@ -212,11 +215,7 @@ func (r *TrieRouter) Find(method, path string, ctx *amaro.Context) (*amaro.Route // 3. CatchAll if n.catchAllNode != nil { if ctx != nil { - value := part - if len(searchPath) > 0 { - value += "/" + searchPath - } - ctx.AddParam(n.catchAllName, value) + ctx.AddParam(n.catchAllName, currentPath) } if n.catchAllNode.Handler != nil { return &n.catchAllNode.Route, nil