Fixes #20601
Change-Id: I296d50dc5210a735a2a65d64bfef05d14c93057b
Reviewed-on: https://go-review.googlesource.com/45073
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rhys Hiltner <rhys@justin.tv>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
// Deep copy the URL because it isn't
// a map and the URL is mutable by users
// of WithContext.
- r2URL := new(url.URL)
- *r2URL = *r.URL
- r2.URL = r2URL
+ if r.URL != nil {
+ r2URL := new(url.URL)
+ *r2URL = *r.URL
+ r2.URL = r2URL
+ }
return r2
}
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