Skip to content

Commit 2024b37

Browse files
committed
HiddenHttpMethodFilter defensively proceeds with original request in case of error dispatch
Issue: SPR-15179 (cherry picked from commit a0df36d)
1 parent fb31919 commit 2024b37

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

spring-web/src/main/java/org/springframework/web/filter/HiddenHttpMethodFilter.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626

2727
import org.springframework.util.Assert;
2828
import org.springframework.util.StringUtils;
29+
import org.springframework.web.util.WebUtils;
2930

3031
/**
3132
* {@link javax.servlet.Filter} that converts posted method parameters into HTTP methods,
@@ -44,6 +45,7 @@
4445
* <i>before</i> this HiddenHttpMethodFilter in your {@code web.xml} filter chain.
4546
*
4647
* @author Arjen Poutsma
48+
* @author Juergen Hoeller
4749
* @since 3.0
4850
*/
4951
public class HiddenHttpMethodFilter extends OncePerRequestFilter {
@@ -67,15 +69,16 @@ public void setMethodParam(String methodParam) {
6769
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
6870
throws ServletException, IOException {
6971

70-
String paramValue = request.getParameter(this.methodParam);
71-
if ("POST".equals(request.getMethod()) && StringUtils.hasLength(paramValue)) {
72-
String method = paramValue.toUpperCase(Locale.ENGLISH);
73-
HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method);
74-
filterChain.doFilter(wrapper, response);
75-
}
76-
else {
77-
filterChain.doFilter(request, response);
72+
HttpServletRequest requestToUse = request;
73+
74+
if ("POST".equals(request.getMethod()) && request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) == null) {
75+
String paramValue = request.getParameter(this.methodParam);
76+
if (StringUtils.hasLength(paramValue)) {
77+
requestToUse = new HttpMethodRequestWrapper(request, paramValue);
78+
}
7879
}
80+
81+
filterChain.doFilter(requestToUse, response);
7982
}
8083

8184

@@ -89,7 +92,7 @@ private static class HttpMethodRequestWrapper extends HttpServletRequestWrapper
8992

9093
public HttpMethodRequestWrapper(HttpServletRequest request, String method) {
9194
super(request);
92-
this.method = method;
95+
this.method = method.toUpperCase(Locale.ENGLISH);
9396
}
9497

9598
@Override

0 commit comments

Comments
 (0)