Skip to content

net/url: clarify in docs that RawPath is not always set by Parse() #29662

@clausti

Description

@clausti

The documentation for the URL type states that

The Parse function sets both Path and RawPath in the URL it returns, and URL's String method uses RawPath if it is a valid encoding of Path, by calling the EscapedPath method. [emphasis added]

which makes it sound like it will always be set but this is not the case.

In the parse() function called by Parse() and ParseRequestURI(), a comment states that it sets Path

and, optionally, RawPath. [...] We don't want to set it if the default escaping of Path is equivalent, to help make sure that people don't rely on it in general. [emphasis added]

For example:
Parsing "/foo" sets Path as "/foo" but does not set RawPath.
Parsing "%2Ffoo" sets the same Path, "/foo", but also sets RawPath as "%2Ffoo".
(see: https://play.golang.org/p/8R2_iCLDdrS)

This is unexpected behavior based on the public package documentation, which should be updated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions