Merge b5ce17c2be2e1289f49c7ca58c2f40f434126980 into dcaa4296d111981ffb31ac3eba90bb63e1eb5ab9

This commit is contained in:
Harshal Patel 2026-08-20 17:17:10 +08:00 committed by GitHub
commit d06aa74f6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 81 additions and 0 deletions

View File

@ -3955,3 +3955,62 @@ func BenchmarkGetMapFromFormData(b *testing.B) {
})
}
}
func TestWildcardParamUnicodeConcurrency(t *testing.T) {
router := New()
var mu sync.Mutex
var errs []string
router.GET("/user/:name", func(c *Context) {
name := c.Param("name")
if name == "" {
mu.Lock()
errs = append(errs, "name param is empty")
mu.Unlock()
}
})
router.GET("/files/*filepath", func(c *Context) {
filepath := c.Param("filepath")
if filepath == "" {
mu.Lock()
errs = append(errs, "filepath param is empty")
mu.Unlock()
}
})
var wg sync.WaitGroup
paths := []string{
"/user/जयेश",
"/files/🎉/photo.png",
"/user/こんにちは",
}
for i := 0; i < 20; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for _, p := range paths {
req, err := http.NewRequest(http.MethodGet, p, nil)
if err != nil {
mu.Lock()
errs = append(errs, "failed to create request: "+err.Error())
mu.Unlock()
continue
}
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusOK {
mu.Lock()
errs = append(errs, "status code is not 200")
mu.Unlock()
}
}
}()
}
wg.Wait()
assert.Empty(t, errs)
}

View File

@ -509,6 +509,11 @@ walk: // Outer loop for walking the tree
// Expand slice within preallocated capacity
i := len(*value.params)
*value.params = (*value.params)[:i+1]
// Ensure 'end' index lands exactly on a valid UTF-8 rune boundary
for end > 0 && end < len(path) && !utf8.RuneStart(path[end]) {
end--
}
val := path[:end]
if unescape {
if v, err := url.QueryUnescape(val); err == nil {

View File

@ -1111,3 +1111,20 @@ func TestTreeFindCaseInsensitivePathWildcardParamAndStaticChild(t *testing.T) {
t.Errorf("Wrong result for '/prefix/something': %s", string(out))
}
}
func TestTreeWildcardParamImproperBoundaryCoverage(t *testing.T) {
tree := &node{}
// Register a path with a wild named parameter segment
tree.addRoute("/submit/:info", HandlersChain{func(c *Context) {}})
// Pass a path containing a multi-byte sequence where a standard byte segment lookup
// drifts directly into the middle of a continuation block.
// This exercises our inner boundary alignment decrement loop.
path := "/submit/जय"
value := tree.getValue(path, &Params{}, nil, false)
if value.handlers == nil {
t.Errorf("Routing fallback failed on multi-byte parameter verification evaluation.")
}
}