fix: Critical routing bug - param nodes with multiple static children (v0.3.3) #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes critical routing bug where routes with
:paramfollowed by multiple static segments would panic.Problem
Routes like
/users/:id/activate+/users/:id/deactivatecaused panic at line 147 intree.go:Root Cause
Common prefix check compared
/deactivatewith:idand found no match.Solution
Implemented httprouter's production-quality pattern:
n.children = []*node{child}) to allow empty path placeholdersChanges
internal/radix/tree.go(lines 118-138): Added special case handling for param node childreninternal/radix/tree_param_static_test.go(new file): 6 comprehensive test casesCHANGELOG.md: Documented v0.3.3 releaseTesting
✅ All 650+ tests passing with race detector (WSL2 Gentoo)
✅ Coverage: 88.4% internal/radix, 91.7% overall (maintained)
✅ Linter: 0 issues (golangci-lint clean)
✅ Performance: No regressions (256 ns/op static, 326 ns/op parametric)
✅ CI: GREEN
Test Cases Added
TestTree_ParamWithMultipleStaticChildren- Original bug caseTestTree_NestedParams- Nested params (/users/:user_id/posts/:post_id/comments)TestTree_AlternatingParamStatic- Alternating pattern (/a/:b/c/:d/e)TestTree_ParamWithLongStaticTail- Long static tails (/:a/b/c/d/e/f/g)TestTree_ConsecutiveParams- Consecutive params (/:a/:b/:c/d)TestTree_StaticVsParam- Static priority over paramsReference
Studied httprouter implementation (
tree.golines 217-270, 180-184) for production-quality reference solution.Checklist