Skip to content

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

@moraes

Description

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions