Description
Hannes Schmidt opened SPR-8662 and commented
The basic problem is that UriTemplate first substitutes the template variables into a single string and then encodes that string as a whole using URIUtils. This simply can't work reliably because the substitution could produce a string that is impossible to parse using a regular expression for URLs. For example, the following template
http://foo.com/things/{thingId}
with the following value for thingId
a/b
produces the following string after substitution
http://foo.com/things/a/b
When URIUtil does not encode the / between a and b because it takes the slash literally. This is what I would expect in this case:
http://foo.com/things/a%2Fb
The reason we have URL-encoding is so we can embed any string into a URL without breaking it. But we need to encode the embedded string BEFORE we embed it. We can't expect URIUtils to be able to fix a URL that we broke by embedding an unencoded string.
Now, depending on where we embed a string into a URL certain characters loose their special meaning. The slash, for example, has no special meaning in the query part. If we want to produce URLs without redundantly encoded parts, we need to take the context into account. Nevertheless, it is always safe to encode all special characters in each embedded string and that would be a simple fix.
Affects: 3.0.5
Issue Links:
- UriTemplate doesn't encode query parameters [SPR-8403] #13050 UriTemplate doesn't encode query parameters
- INT-2569 Refactor HttpOutboundGateway to mitigate breaking changes due to UriTemplate changes in Spring 3.1