Skip to content

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

Closed

Description

@rsc

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

Activity

  1. added this to the Go1.9Maybe milestone on Apr 20, 2017
  2. bradfitz commented on Apr 20, 2017

    @bradfitz
    Contributor

    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.

  3. rsc commented on Apr 20, 2017

    @rsc
    ContributorAuthor

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

  4. dsnet commented on Apr 20, 2017

    @dsnet
    Member

    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?

  5. rsc commented on Apr 20, 2017

    @rsc
    ContributorAuthor

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

  6. johnnyluo commented on Jul 15, 2017

    @johnnyluo
    Contributor

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

  7. assigned and unassigned on Jul 15, 2017
  8. gopherbot commented on Jul 16, 2017

    @gopherbot
    Contributor

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

  9. odeke-em commented on Jul 19, 2017

    @odeke-em
    Member

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

  10. modified the milestones: Go1.10, Go1.9Maybe on Jul 19, 2017
  11. johnnyluo commented on Aug 29, 2017

    @johnnyluo
    Contributor

    @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.

  12. odeke-em commented on Aug 29, 2017

    @odeke-em
    Member

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

  13. locked and limited conversation to collaborators on Aug 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions