Skip to content

net/url: encoding is broken as per RFC wrt @ #9594

@devonjones

Description

@devonjones

https://tools.ietf.org/html/rfc3986 2.2: Reserved characters: @ is a reserved character, the only place it should be in the url is between username@host

What version of Go are you using (go version)?

  • Current version of the go playground

What operating system and processor architecture are you using?

  • Current version of the go playground

What did you do?
What did you expect to see?
What did you see instead?

http://play.golang.org/p/WvjfmMKJIw

package main

import (
    "fmt"
    "net/url"
)

func main() {

    var Url *url.URL
    Url, err := url.Parse("http://www.example.com")
    if err != nil {
        panic("boom")
    }

    Url.Path += "/users/1/recipients/devon.jones@sendgrid.com"
    fmt.Printf("Encoded URL is %q\n", Url.String())
}
Encoded URL is "http://www.example.com/users/1/recipients/devon.jones@sendgrid.com"

shows that if I url encode with @ in the path, it leaves it. But if I use other reserved characters, like ?, it will properly encode them:

http://play.golang.org/p/FT-JyJ-DnG

package main

import (
    "fmt"
    "net/url"
)

func main() {

    var Url *url.URL
    Url, err := url.Parse("http://www.example.com")
    if err != nil {
        panic("boom")
    }

    Url.Path += "/users/1/recipients/devon.jones?sendgrid.com"
    fmt.Printf("Encoded URL is %q\n", Url.String())
}
Encoded URL is "http://www.example.com/users/1/recipients/devon.jones%3Fsendgrid.com"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions