Skip to content

net/url: url.RawQuery = url.Query().Encode() can change the URL #16460

@tombergan

Description

@tombergan

In the following code:

u, _ := url.Parse("http://www.example.com/path?foo")
fmt.Println(u)
u.RawQuery = u.Query().Encode()
fmt.Println(u)

The third line actually changes the URL. The output is:

http://www.example.com/path?foo
http://www.example.com/path?foo=

A strict reading of RFC 3986 Section 6 suggests that these are two different URLs even after applying the (optional) syntax-based normalizations described in Section 6.2.2. I know of some servers that consider these URLs different. For example, compare the following links:

http://www.vcfed.org/forum/forumdisplay.php?23-DEC
http://www.vcfed.org/forum/forumdisplay.php?23-DEC=

I consider this a bug, but I doubt we could fix this bug in a backwards-compatible way. At least, I think we should update the documentation to make it clear that url.Query().Encode() can change query param "foo" to "foo=", which may be considered a different URL by some servers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions