From 2da39e3037cd040a6cc25c79e00a6fd808471174 Mon Sep 17 00:00:00 2001 From: Suryakant Sahoo <230859682+suryakant-source@users.noreply.github.com> Date: Sat, 24 Oct 2026 07:53:25 +0530 Subject: [PATCH] test: cover trailing-slash redirect with a skipped wildcard node --- tree_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tree_test.go b/tree_test.go index 23339af4..122e25e6 100644 --- a/tree_test.go +++ b/tree_test.go @@ -711,6 +711,33 @@ func TestRedirectTrailingSlash(t *testing.T) { } } +func TestRedirectTrailingSlashWithSkippedWildcard(t *testing.T) { + // Regression test for #4890: when a wildcard route makes the walk roll back + // to a skipped node, the static branch's trailing-slash recommendation must + // not be lost (a 301 to /aa/ is expected, not a 404). + tr := &node{} + tr.addRoute("/:c/bb", fakeHandler("/:c/bb")) + tr.addRoute("/aa/", fakeHandler("/aa/")) + tr.addRoute("/aa_id", fakeHandler("/aa_id")) + + value := tr.getValue("/aa", nil, getSkippedNodes(), false) + if value.tsr != true { + t.Fatalf("want true, is false") + } + if value.handlers != nil { + t.Fatalf("want no handlers for /aa") + } + + // A wildcard branch that does match still wins over the redirect. + tr2 := &node{} + tr2.addRoute("/:c/bb", fakeHandler("/:c/bb")) + tr2.addRoute("/aa/", fakeHandler("/aa/")) + value2 := tr2.getValue("/aa/bb", nil, getSkippedNodes(), false) + if value2.handlers == nil { + t.Fatalf("wildcard route /:c/bb no longer matched") + } +} + func TestTreeFindCaseInsensitivePath(t *testing.T) { tree := &node{}