Commit a9216a0a authored by Johnny Luo's avatar Johnny Luo Committed by Joe Tsai

net/url: make Parse+String round trip magnet URLs

Fixes #20054

Change-Id: I3c660ca0c56cdde2c2ac2f6a666d8531ab5588c5
Reviewed-on: https://go-review.googlesource.com/49050
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJoe Tsai <thebrokentoaster@gmail.com>
parent 4d269ad1
......@@ -726,7 +726,9 @@ func (u *URL) String() string {
buf.WriteString(u.Opaque)
} else {
if u.Scheme != "" || u.Host != "" || u.User != nil {
buf.WriteString("//")
if u.Host != "" || u.Path != "" || u.User != nil {
buf.WriteString("//")
}
if ui := u.User; ui != nil {
buf.WriteString(ui.String())
buf.WriteByte('@')
......
......@@ -568,6 +568,28 @@ var urltests = []URLTest{
},
"",
},
// test we can roundtrip magnet url
// fix issue https://golang.org/issue/20054
{
"magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a&dn",
&URL{
Scheme: "magnet",
Host: "",
Path: "",
RawQuery: "xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a&dn",
},
"magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a&dn",
},
{
"mailto:?subject=hi",
&URL{
Scheme: "mailto",
Host: "",
Path: "",
RawQuery: "subject=hi",
},
"mailto:?subject=hi",
},
}
// more useful string for debugging than fmt's struct printer
......
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