Commit 1284d7d4 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick Committed by Russ Cox

net/url: don't escape star requests when writing requests

Includes a new net/http test too.

Fixes #11202

Change-Id: I61edc594f4de8eb6780b8dfa221269dd482e8f35
Reviewed-on: https://go-review.googlesource.com/11492Reviewed-by: default avatarDmitry Vyukov <dvyukov@google.com>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 379d8327
...@@ -513,6 +513,32 @@ func TestRequestWriteBufferedWriter(t *testing.T) { ...@@ -513,6 +513,32 @@ func TestRequestWriteBufferedWriter(t *testing.T) {
} }
} }
func TestStarRequest(t *testing.T) {
req, err := ReadRequest(bufio.NewReader(strings.NewReader("M-SEARCH * HTTP/1.1\r\n\r\n")))
if err != nil {
return
}
var out bytes.Buffer
if err := req.Write(&out); err != nil {
t.Fatal(err)
}
back, err := ReadRequest(bufio.NewReader(&out))
if err != nil {
t.Fatal(err)
}
// Ignore the Headers (the User-Agent breaks the deep equal,
// but we don't care about it)
req.Header = nil
back.Header = nil
if !reflect.DeepEqual(req, back) {
t.Errorf("Original request doesn't match Request read back.")
t.Logf("Original: %#v", req)
t.Logf("Original.URL: %#v", req.URL)
t.Logf("Wrote: %s", out.Bytes())
t.Logf("Read back (doesn't match Original): %#v", back)
}
}
func testMissingFile(t *testing.T, req *Request) { func testMissingFile(t *testing.T, req *Request) {
f, fh, err := req.FormFile("missing") f, fh, err := req.FormFile("missing")
if f != nil { if f != nil {
......
...@@ -537,6 +537,9 @@ func (u *URL) EscapedPath() string { ...@@ -537,6 +537,9 @@ func (u *URL) EscapedPath() string {
return u.RawPath return u.RawPath
} }
} }
if u.Path == "*" {
return "*" // don't escape (Issue 11202)
}
return escape(u.Path, encodePath) return escape(u.Path, encodePath)
} }
......
...@@ -1107,6 +1107,17 @@ func TestParseAuthority(t *testing.T) { ...@@ -1107,6 +1107,17 @@ func TestParseAuthority(t *testing.T) {
} }
} }
// Issue 11202
func TestStarRequest(t *testing.T) {
u, err := Parse("*")
if err != nil {
t.Fatal(err)
}
if got, want := u.RequestURI(), "*"; got != want {
t.Errorf("RequestURI = %q; want %q", got, want)
}
}
type shouldEscapeTest struct { type shouldEscapeTest struct {
in byte in byte
mode encoding mode encoding
......
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