Closed
Description
Rodion opened SPR-11101 and commented
Controller method:
@RequestMapping(value = "/test_url_decoding/{param1}")
public String[] testUrlDecoding(@PathVariable("param1") String p1)
Call:
/test_url_decoding/a%2Fb
Expecting result: parameter p1 is set to "a/b".
Current result: 404 Not found.
Simular problem:
http://stackoverflow.com/questions/13482020/encoded-slash-2f-with-spring-requestmapping-path-param-gives-http-400
The problem was already discussed in https://jira.springsource.org/browse/SPR-7919
Suggested solution (setting decodeUrl of the HandlerMapping to false) does not work. The UrlPathHelper uses HttpServletRequest.getServletPath() method internally, which decodes the path.
Suggested implementation for non-decoding helper:
public class UrlPathHelperNonDecoding extends UrlPathHelper {
public UrlPathHelperFixed() {
super.setUrlDecode(false);
}
@Override
public void setUrlDecode(boolean urlDecode) {
if (urlDecode) {
throw new IllegalArgumentException("Handler does not support URL decoding.");
}
}
@Override
public String getServletPath(HttpServletRequest request) {
String servletPath = getOriginatingServletPath(request);
return servletPath;
}
@Override
public String getOriginatingServletPath(HttpServletRequest request) {
String servletPath = request.getRequestURI().substring(request.getContextPath().length());
return servletPath;
}
}
context.xml
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="order" value="-1"></property>
<property name="urlPathHelper">
<bean class="com.yoochoose.frontend.spring.UrlPathHelperFixed"/>
</property>
</bean>
Affects: 3.2.5
Issue Links:
- Request mapping using @PathVariable doesn't work with URL-encoded values [SPR-7919] #12574 Request mapping using
@PathVariable
doesn't work with URL-encoded values - [doc] Document urlDecode=false implies alwaysUseFullPath=true [SPR-15643] #20202 [doc] Document urlDecode=false implies alwaysUseFullPath=true
Referenced from: commits 12598f8, d55a173
Backported to: 3.2.8
3 votes, 10 watchers