Skip to content

proposal: net/url: provide URIEscape method #41922

@kpym

Description

@kpym

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

$ go version
go version go1.15 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

Irrelevant

What did you do?

I want to encode data for Data URI as specified in rfc3986 section 2.4.

For example if I want to use Data URI for svg image like data:image/svg+xml,... the svg code should be escaped. And I don't want to use base64 because this makes the data more than 30% bigger.

What did you expect to see?

I would like to have a function URIEscape (that should be very close to the internal escape(s, encodeZone ) I think).

What did you see instead?

There is PathEscape that can be used to escape the data but such encoded data is bigger than needed because some symbols that do not need escape are percent escaped.

Notes :

  • In JavaScript there exists encodeURI which keeps more unescaped symbols than any of the options in shouldEscape (for example # is unescaped).
  • It seems that the spaces can be preserved even if this is not standard, as explained here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions