Skip to content

URLs containing %2F (forward slash) are not mapped correctly to @RequestMapping methods [SPR-11101] #15727

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 12598f8, d55a173

Backported to: 3.2.8

3 votes, 10 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions