New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: net/url: provide URIEscape method #41922
Comments
Note that if you want an escaped form of a URL, the usual approach is to fill out a url.URL struct and then call its String method. Then each piece is properly escaped, which is not something a single function can do. |
There is also PathEscape and QueryEscape. I am confused why you brought up escapeZone. |
@rsc It depends what you meen by 'appropriate'. I don't think that you can put the data URI in As I said in my question, the data URI allows more characters to be non escaped. |
This proposal has been added to the active column of the proposals project |
What is the specific escaping to be applied? For the body of a data: URL I would expect # to be invalid (and need escaping) since even scheme:opaque URL forms can have #fragment following them, at least according to the url.URL docs. Similarly ? since they can have queries too. So that sounds like PathEscape. The text above says "some symbols" are unnecessarily escaped by PathEscape (at least for use in a data URL). Which symbols specifically? |
@rsc The javascript
But using I don't know anymore if having the equivalent of |
This is probably too specific for the standard library. svg is probably the only case where very few bytes have to be escaped. If we were escaping a png, for example, base64 is probably better than %-encoding all the binary in the png. So any function here would have to let you pick the encoding or just be very niche. |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
What version of Go are you using (
go version
)?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 usebase64
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 internalescape(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 :
encodeURI
which keeps more unescaped symbols than any of the options inshouldEscape
(for example#
is unescaped).The text was updated successfully, but these errors were encountered: