fix: different concreate types still cause panic (#4597)

This commit is contained in:
Kevin Wan
2025-01-25 18:53:32 +08:00
committed by GitHub
parent 114311e51b
commit 44504e8df7
2 changed files with 33 additions and 5 deletions

View File

@@ -734,6 +734,22 @@ func TestParseJsonStringRequest(t *testing.T) {
})
}
type valid1 struct{}
func (v valid1) Validate(*http.Request, any) error { return nil }
type valid2 struct{}
func (v valid2) Validate(*http.Request, any) error { return nil }
func TestSetValidatorTwice(t *testing.T) {
// panic: sync/atomic: store of inconsistently typed value into Value
assert.NotPanics(t, func() {
SetValidator(valid1{})
SetValidator(valid2{})
})
}
func BenchmarkParseRaw(b *testing.B) {
r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello&age=18&percent=3.4", http.NoBody)
if err != nil {