Fixes #24297
Change-Id: I759e88655632fda97dced240b3f13392b2785d0a
Reviewed-on: https://go-review.googlesource.com/99575
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
}
}
+// Issue 24297
+func TestServeMuxHandleFuncWithNilHandler(t *testing.T) {
+ setParallel(t)
+ defer func() {
+ if err := recover(); err == nil {
+ t.Error("expected call to mux.HandleFunc to panic")
+ }
+ }()
+ mux := NewServeMux()
+ mux.HandleFunc("/", nil)
+}
+
var serveMuxTests2 = []struct {
method string
host string
// HandleFunc registers the handler function for the given pattern.
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
+ if handler == nil {
+ panic("http: nil handler")
+ }
mux.Handle(pattern, HandlerFunc(handler))
}