--
You received this message because you are subscribed to the Google Groups "Ring" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-clojure...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Ring has two functions:
- ring.util.codec/url-encode
- ring.util.codec/form-encode
The form-encode function does what you want it to do, in that it translates "+" into "%2B". It will also translate maps of parameters.The url-encode function, on the other hand, doesn't translate "+" because it's not an invalid character, and technically shouldn't be encoded in most circumstances. In particular, it can be used without encoding within the path of the URL (see section 3.3 of RFC 3986). For instance, you could have a URL like "http://example.com/buy+sell".
2.3. Unreserved Characters
Characters that are allowed in a URI but do not have a reserved
purpose are called unreserved. These include uppercase and lowercase
letters, decimal digits, hyphen, period, underscore, and tilde.
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
URL encode the parameter name and values according to the following rules:
Do not URL encode any of the unreserved characters that RFC 3986 defines.
These unreserved characters are A-Z, a-z, 0-9, hyphen ( - ), underscore ( _ ), period ( . ), and tilde ( ~ ).
Percent encode all other characters with %XY, where X and Y are hex characters 0-9 and uppercase A-F.
Percent encode extended UTF-8 characters in the form %XY%ZA....
Percent encode the space character as %20 (and not +, as common encoding schemes do).
On Wednesday, December 18, 2013 12:47:10 PM UTC+1, James Reeves wrote:The url-encode function, on the other hand, doesn't translate "+" because it's not an invalid character, and technically shouldn't be encoded in most circumstances. In particular, it can be used without encoding within the path of the URL (see section 3.3 of RFC 3986). For instance, you could have a URL like "http://example.com/buy+sell".Sigh. I think there is a lot of confusion around this and the RFC leaves much to be desired.What I really expect is a strict reading of RFC3986 section 2.3:
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
As for the question of what I am encoding, the answer isn't that obvious. I'm signing AWS requests, which requires merging the query string *and* request POST params. See for example http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/HMACAuth.html#REST_RESTAuth:
URL encode the parameter name and values according to the following rules:
Do not URL encode any of the unreserved characters that RFC 3986 defines.
These unreserved characters are A-Z, a-z, 0-9, hyphen ( - ), underscore ( _ ), period ( . ), and tilde ( ~ ).
Percent encode all other characters with %XY, where X and Y are hex characters 0-9 and uppercase A-F.
Percent encode extended UTF-8 characters in the form %XY%ZA....
Percent encode the space character as %20 (and not +, as common encoding schemes do).
(defn aws-url-encode [unencoded & [encoding]](str/replaceunencoded#"[^A-Za-z0-9_~.-]+"#(double-escape (percent-encode % encoding))))
/base/12345/John/pages/5/en?format=json&q=URI%20Templates