Skip to content
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

net/url: issue with encoding spaces #4013

Closed
gopherbot opened this issue Aug 28, 2012 · 4 comments
Closed

net/url: issue with encoding spaces #4013

gopherbot opened this issue Aug 28, 2012 · 4 comments

Comments

@gopherbot
Copy link

by tech163@sliceone.com:

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. http://play.golang.org/p/Hal0slZDI9

What is the expected output?

Tue%20Aug%2028%2013%3A52%3A20%20UTC%202012

What do you see instead?

Tue+Aug+28+13%3A52%3A20+UTC+2012

Which version are you using?  (run 'go version')

go version go1.0.2 (appengine-1.7.1)

Please provide any additional information below.

http://golang.org/pkg/net/url/ says "Package url parses URLs and implements query
escaping. See RFC 3986.", and spaces ' ' should be %20 rather than +
@minux
Copy link
Member

minux commented Aug 29, 2012

Comment 1:

QueryEscape escape the query part of the URL,
and a space in query is escaped as +.

Status changed to WorkingAsIntended.

@Grovespaz
Copy link

Comment 2:

Is that actually specified somewhere?
net/url assumes a query parameter to follow application/x-www-form-urlencoded rules
instead of RFC's.
RFC1738 defines + as an allowed character but doesn't specify it to be a space, even
though it is commonly regarded as such.
RFC3986 seems to recommend %20 for spaces.
net/url makes a special case out of the space, even though url.go refers to RFC3986.
If I recall correctly the + sign is used when a browser submits a form to an url, for
legacy reasons(?) when using mime-type 'application/x-www-form-urlencoded'.
This is, however, not part of an RFC?
So both forms are in use and both appear to be syntactically correct (even though using
the + sign is older but more readable), so when encoding one just has to choose.
See also:
http://en.wikipedia.org/wiki/Percent-encoding#The_application.2Fx-www-form-urlencoded_type

@gopherbot
Copy link
Author

Comment 3 by psnim2000:

It seems that the query portion can be escaped as "%20" or "+" and the path portion can
only be escaped as "%20".
I was using this function to generate paths and because "+" did not become spaces,
according the browser, there was an unintended consequence.
It seems to me it would be better to have it encode to "%20" as they work for both cases.

mrmiroslav pushed a commit to mrmiroslav/amazing that referenced this issue May 6, 2015
AWS Signature V2 used in Product Advertising API (API Version 2013-08-01) is using %20 for space encoding within signature, where is golang uses +. This produces a signature mismatch when amazon verifies signature.

References:
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/RESTSyntax.html
golang/go#4013
@imax9000
Copy link

API for proper percent-encoding would be still nice to have.

@mikioh mikioh changed the title net/url issue with encoding spaces net/url: issue with encoding spaces Jun 13, 2015
@golang golang locked and limited conversation to collaborators Jan 17, 2017
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants