From 7579f96676eb2ea932cfa02e805bbae02c0d310c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 7 Jun 2017 18:13:38 +0000 Subject: net/http: don't crash in Request.WithContext if Request.URL is nil Fixes #20601 Change-Id: I296d50dc5210a735a2a65d64bfef05d14c93057b Reviewed-on: https://go-review.googlesource.com/45073 Run-TryBot: Brad Fitzpatrick Reviewed-by: Rhys Hiltner Reviewed-by: Emmanuel Odeke Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/request_test.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/net/http/request_test.go') diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go index 1608d1c4fe..967156bac9 100644 --- a/src/net/http/request_test.go +++ b/src/net/http/request_test.go @@ -799,6 +799,13 @@ func TestWithContextDeepCopiesURL(t *testing.T) { if firstURL == secondURL { t.Errorf("unexpected change to original request's URL") } + + // And also check we don't crash on nil (Issue 20601) + req.URL = nil + reqCopy = req.WithContext(context.Background()) + if reqCopy.URL != nil { + t.Error("expected nil URL in cloned request") + } } // verify that NewRequest sets Request.GetBody and that it works -- cgit v1.3