This commit simply adds a @PathVariable decoding test to reproduce a scenario exposed in SPR-11474

Issue: SPR-11474

Comment From: rstoyanchev

Since this is an encoding-related issue, an integration test would be best (vs relying on MockHttpServletRequest/Reponse). The spring-framework-issues repository is the place to go to when confirming if something is an issue or not.

Comment From: snicoll

Good point. Let me create that project.

Comment From: snicoll

Rossen, I tried to create an IT for this particular problem so that we can validate this in our own infrastructure automatically. Unfortunately, I have issues to reproduce the scenario using the embedded Jetty server.

While the requests seem to be the same, the server does not decode the URI at all (i.e. HttpServletRequest#getServletPath returns the encoded URL instead of decoding it).

Anyway, I hope it will be useful as a base IT for this issue.

Comment From: snicoll

The servlet spec states that ServletRequest#getCharacterEncoding provides the character encoding of the body of the request and if none is specified, latin should be used (i.e. ISO-8859-1).

UrlPathHelper builds on top of this mechanism to decode URIs but it shouldn't assume that the character encoding of the body should be used if specified as this is a different matter. Typically, servlet containers decode the URI with UTF-8 and never use the character encoding of the body.

This commit clarifies the situation in a way that better matches the spec. A new property called uriEncoding allows to force the encoding to use. The defaultEncoding property is now deprecated and only used if no uriEncoding is set. For backward compatible reasons, uriEncoding is not set by default.

Comment From: rstoyanchev

Typically, servlet containers decode the URI with UTF-8

If Tomcat uses ISO-8859-1 by default I'm not sure it is very typical.

Comment From: snicoll

Good point, let me amend the commit.

Comment From: snicoll

Closing a PR that I created a couple of months after joining 😬 - Kidding aside, this got superseded by #16543