Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

net/url: Parse+String does not round trip magnet URLs #20054

rsc opened this Issue Apr 20, 2017 · 9 comments


None yet
6 participants

rsc commented Apr 20, 2017

I received a private email with a report that Go inserts // in magnet URLs.
That appears to mean https://en.wikipedia.org/wiki/Magnet_URI_scheme.
Round-tripping the example from that wikipedia page:

package main

import (

func main() {


magnet://?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a&dn <nil>


It does seem like the leading // should not be there. However, I don't know how much this matters, nor how invasive this would be to fix, nor whether the // insertion is correct for any other schemes (in particular, http and https).

/cc @bradfitz

@rsc rsc added this to the Go1.9Maybe milestone Apr 20, 2017


bradfitz commented Apr 20, 2017

We don't special case mailto: so it'd be nice to not special case magnet:.

But perhaps we could tweak our heuristics for URL.String's Opaque-vs-:// forms.


rsc commented Apr 20, 2017

Hmm, so mailto:rsc?subject=hi round-trips but mailto:?subject=hi turns into mailto://?subject=hi.


dsnet commented Apr 20, 2017

Part of the problem is that we parse the Opaque field out as the empty string. When we try to round trip, we notice that the Opaque field is empty and assume it's a hierarchical URL, which it is not. Perhaps, we should add a ForceOpaque bool field?


rsc commented Apr 20, 2017

I would rather not add a new bool.

If u.User == nil && u.Host=="" && u.Path=="", can we print that part as an empty string instead of as //?


johnnyluo commented Jul 15, 2017

I am interested to work on this one, can someone assign it to me? so other people won't waste time on this

@dsnet dsnet assigned dsnet and unassigned dsnet Jul 15, 2017

CL https://golang.org/cl/49050 mentions this issue.


odeke-em commented Jul 19, 2017

Moving this to Go1.10 as per the CL update and given how deep we are in the freeze Go1.9.

@odeke-em odeke-em modified the milestones: Go1.10, Go1.9Maybe Jul 19, 2017


johnnyluo commented Aug 29, 2017

@dsnet @odeke-em could you guys please help to run trybot on CL https://golang.org/cl/49050, the previous trybot failed , however it is nothing to do with my change.


odeke-em commented Aug 29, 2017

Thanks for the ping @johnnyluo, I've ran the trybot.

@gopherbot gopherbot closed this in a9216a0 Aug 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment