]> Cypherpunks repositories - gostls13.git/commitdiff
net/url: make Parse+String round trip magnet URLs
authorJohnny Luo <johnnyluo1980@gmail.com>
Sun, 16 Jul 2017 00:39:11 +0000 (10:39 +1000)
committerJoe Tsai <thebrokentoaster@gmail.com>
Thu, 31 Aug 2017 01:45:17 +0000 (01:45 +0000)
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>
src/net/url/url.go
src/net/url/url_test.go

index 00e0df17ba4dab5b2fb61c092a2dd27d01e6aede..c9353ab080d72abaf669ab8874037982a737e8ce 100644 (file)
@@ -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('@')
index 6c3bb21d20cb367d8823b364e91ed8f69c349af3..5f03200d94bd2aca6cd85d44c5c66ad3a00b6dc5 100644 (file)
@@ -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