Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/url: Parse("#foo") should not result in error #4700

Closed
moraes opened this issue Jan 24, 2013 · 7 comments
Closed

net/url: Parse("#foo") should not result in error #4700

moraes opened this issue Jan 24, 2013 · 7 comments
Milestone

Comments

@moraes
Copy link
Contributor

moraes commented Jan 24, 2013

Currently url.Parse("#foo") results in an error. It should result in a url.URL
with only the Fragment field set, like when you get the RawQuery field set after calling
url.Parse("?foo").

URIs that include only a fragment are described by the RFC [1]:

    The most frequent examples of same-document references are 
    relative references that are empty or include only the number 
    sign ("#") separator followed by a fragment identifier. 

And of course "#foo" is a valid href value in an HTML document. It gets more
curious: "" is also a same-document reference, so should
url.Parse("") be allowed?

Imagine that for web-scrapping, you define a function that merges the document URL with
the href values it finds. This function can't receive *url.URL as argument, because
url.Parse("#foo") and url.Parse("") both result in error, despite
being meaningful href values.

[1] http://tools.ietf.org/html/rfc3986#section-4.4
@bradfitz
Copy link
Contributor

Comment 1:

Does http://golang.org/pkg/net/url/#URL.Parse behave differently?

@gopherbot
Copy link

Comment 2 by Lytvynov.A.V:

Seems like no, http://play.golang.org/p/rGuL0uGSZf

@moraes
Copy link
Contributor Author

moraes commented Jan 24, 2013

Comment 3:

URL.Parse does quite well in the weird examples from RFC 3986, but "" or "#fragment"
result in error: http://play.golang.org/p/F0ApSaXniv

@moraes
Copy link
Contributor Author

moraes commented Jan 24, 2013

Comment 4:

Now, the question is if accepting "" and "#foo" in url.Parse or URL.Parse (or both) is
an API break or a bug fix. :)
Let me know. I can provide a patch and if interested, make those RFC examples pass.

@moraes
Copy link
Contributor Author

moraes commented Jan 25, 2013

Comment 5:

I'd like to implement this in Parse(), so that URL.ResolveReference() could also do this
kind of resolution. But I'm afraid that this would be considered an API break, so I
implemented it in URL.Parse for now:
https://golang.org/cl/7205056
The RFC examples I mentioned in comment 3 are solved in issue #4706.

@rsc
Copy link
Contributor

rsc commented Jan 30, 2013

Comment 6:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Mar 11, 2013

Comment 7:

This issue was closed by revision 82e3ca7.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants