Commit 3afbb690 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/url: fix parsing of URLs ending in question mark

Fixes parsing regression from https://golang.org/cl/19931 which
added the URL.ForceQuery field.

Fixes #14573

Change-Id: I89575cab3f778b1bf78b2389623c866450b26943
Reviewed-on: https://go-review.googlesource.com/20116
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAndrew Gerrand <adg@golang.org>
parent 37c29727
......@@ -461,7 +461,7 @@ func parse(rawurl string, viaRequest bool) (url *URL, err error) {
}
url.Scheme = strings.ToLower(url.Scheme)
if strings.HasSuffix(rest, "?") {
if strings.HasSuffix(rest, "?") && strings.Count(rest, "?") == 1 {
url.ForceQuery = true
rest = rest[:len(rest)-1]
} else {
......
......@@ -83,6 +83,17 @@ var urltests = []URLTest{
},
"",
},
// query ending in question mark (Issue 14573)
{
"http://www.google.com/?foo=bar?",
&URL{
Scheme: "http",
Host: "www.google.com",
Path: "/",
RawQuery: "foo=bar?",
},
"",
},
// query
{
"http://www.google.com/?q=go+language",
......@@ -564,8 +575,8 @@ func ufmt(u *URL) string {
pass = p
}
}
return fmt.Sprintf("opaque=%q, scheme=%q, user=%#v, pass=%#v, host=%q, path=%q, rawpath=%q, rawq=%q, frag=%q",
u.Opaque, u.Scheme, user, pass, u.Host, u.Path, u.RawPath, u.RawQuery, u.Fragment)
return fmt.Sprintf("opaque=%q, scheme=%q, user=%#v, pass=%#v, host=%q, path=%q, rawpath=%q, rawq=%q, frag=%q, forcequery=%v",
u.Opaque, u.Scheme, user, pass, u.Host, u.Path, u.RawPath, u.RawQuery, u.Fragment, u.ForceQuery)
}
func DoTest(t *testing.T, parse func(string) (*URL, error), name string, tests []URLTest) {
......
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