Commit 7d654af5 authored by Kunpei Sakai's avatar Kunpei Sakai Committed by Brad Fitzpatrick

net/http: panic when a nil handler is passed to (*ServeMux)HandleFunc

Fixes #24297

Change-Id: I759e88655632fda97dced240b3f13392b2785d0a
Reviewed-on: https://go-review.googlesource.com/99575Reviewed-by: 's avatarAndrew Bonventre <andybons@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 9f2c611f
......@@ -379,6 +379,18 @@ func TestServeMuxHandler(t *testing.T) {
}
}
// 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
......
......@@ -2358,6 +2358,9 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
// 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))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment