URL path segment encoding
Java’s URLEncoder
class is not suitable for encoding path segments in URLs. It’s not even really suitable for encoding GET parameters in the query part of a URL, e.g. it encodes unreserved URI characters, which should not be encoded, such as tilde (~).
Spring has a good encoder. Now Play does too. :)
- URL Living Standard
- RFC 3986 (obsoletes/updates RFC 1738 and RFC 2396).
- application/x-www-form-urlencoded
- A couple of good summaries: Wikipedia on percent encoding, Lunatech’s What every web developer must know about URL encoding.
RFC 1738 is obsolete, so don’t just go and percent-encode the characters it lists as unsafe. Encoding such characters may violate the newer RFC 3986. Ignore instructions that say otherwise!