Add validation of HTTP method in form tag

SPR-6945
This commit is contained in:
Rossen Stoyanchev 2012-05-14 11:38:58 -04:00
parent f1a699cff5
commit 59084354e2
1 changed files with 11 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import javax.servlet.jsp.PageContext;
import org.springframework.beans.PropertyAccessor;
import org.springframework.core.Conventions;
import org.springframework.http.HttpMethod;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.support.RequestDataValueProcessor;
@ -319,7 +320,6 @@ public class FormTag extends AbstractHtmlElementTag {
return ("get".equalsIgnoreCase(method) || "post".equalsIgnoreCase(method));
}
/**
* Writes the opening part of the block '<code>form</code>' tag and exposes
* the form object name in the {@link javax.servlet.jsp.PageContext}.
@ -345,6 +345,7 @@ public class FormTag extends AbstractHtmlElementTag {
tagWriter.forceBlock();
if (!isMethodBrowserSupported(getMethod())) {
assertHttpMethod(getMethod());
String inputName = getMethodParameter();
String inputType = "hidden";
tagWriter.startTag(INPUT_TAG);
@ -369,6 +370,15 @@ public class FormTag extends AbstractHtmlElementTag {
return EVAL_BODY_INCLUDE;
}
private void assertHttpMethod(String method) {
for (HttpMethod httpMethod : HttpMethod.values()) {
if (httpMethod.name().equalsIgnoreCase(method)) {
return;
}
}
throw new IllegalArgumentException("Invalid HTTP method: " + method);
}
/**
* Autogenerated IDs correspond to the form object name.
*/