mirror of
https://github.com/golang/go
synced 2024-11-19 21:54:40 -07:00
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: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
parent
4d269ad175
commit
a9216a0ade
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user