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

URL encoding of whitespace should be "%20" instead of "+" in query parameters #626

Open
viesti opened this issue Nov 29, 2022 · 1 comment

Comments

@viesti
Copy link

viesti commented Nov 29, 2022

Hi!

I ran into the following when talking to AWS SQS, when I sent data like

:query-params {"Action" "SendMessage"
               "MessageBody" "foo bar"}

which get's encoded into

:query-string "Action=SendMessage&MessageBody=foo+bar",

which the SQS service then rejects, because the whitespace in the foo bar should be encoded as %20 in the query parameter, instead of +.

I think that " " => "+" in query parameter is allowed by some services, since I didn't find an issue in this repository for this behavior, but strictly speaking, in URL encoding, the whitespace character should be encoded as %20.

clj-http uses java.net.URLEncoder and java.net.URLDecoder for both form and url encoding/decoding, but URLEncoder/URLDecoder documentation says:

Utility class for HTML form encoding.

Ring-Codec has utilities for both url and form encoding/decoding:

user> (ring.util.codec/url-encode " ")
"%20"
user> (ring.util.codec/form-encode " ")
"+"

So I guess ring-codec could be used.

@viesti
Copy link
Author

viesti commented Nov 29, 2022

Noting that a workaround, if one happens to run into this issue, is to append the query parameters to the URL, and ring.util.codec/url-encode can be used then for encoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant