Skip to content

net/url: No adequate method exists for encoding a URI component #16207

@alienth

Description

@alienth
  1. What version of Go are you using (go version)?
    1.6.2
  2. What operating system and processor architecture are you using (go env)?
    linux amd64
  3. What did you do?
    https://play.golang.org/p/loaa8vvCli
    Attempted to use net/url to encode a component of a URI which contained both forward-slashes and whitespace.
  4. What did you expect to see?
    A method akin to JS encodeURIcomponent which would encode the component the way I need.
  5. What did you see instead?
    No solution, as of yet.

I'm interacting with an API where I need to escape individual URI components. In my specific case, I'm escaping components containing whitespace and forward slashes. As demonstrated above, net/url seems to have no method which I can use to accomplish this. Any url.Parse() related function will ignore forward slashes, as it should. I also can't rely on something such as url.QueryParse(), as query string encoding turns whitespace into +.

Would it be possible for net/url to add functionality akin to JS's encodeURIcomponent to cover cases such as this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions