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

Closed
rsc opened this Issue Apr 20, 2017 · 9 comments

Comments

Projects
None yet
6 participants
Contributor

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 (
	"fmt"
	"net/url"
)

func main() {
	fmt.Println(url.Parse(`magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a&dn`))
}

prints

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

https://play.golang.org/p/OQKMvDyTD-

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

Owner

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.

Contributor

rsc commented Apr 20, 2017

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

Member

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?

Contributor

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 //?

Contributor

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.

Member

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

Contributor

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.

Member

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