Skip to content

Commit 741b4b2

Browse files
committed
Add encoding for the default action in FormTag
Issue: SPR-11426
1 parent 0cb27f4 commit 741b4b2

File tree

2 files changed

+26
-2
lines changed
  • spring-webmvc/src

2 files changed

+26
-2
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.web.servlet.tags.form;
1818

19+
import java.io.UnsupportedEncodingException;
1920
import java.util.Map;
2021

2122
import javax.servlet.ServletRequest;
@@ -32,6 +33,7 @@
3233
import org.springframework.util.StringUtils;
3334
import org.springframework.web.servlet.support.RequestDataValueProcessor;
3435
import org.springframework.web.util.HtmlUtils;
36+
import org.springframework.web.util.UriUtils;
3537

3638
/**
3739
* Databinding-aware JSP tag for rendering an HTML '{@code form}' whose
@@ -442,6 +444,13 @@ else if (StringUtils.hasText(servletRelativeAction)) {
442444
}
443445
else {
444446
String requestUri = getRequestContext().getRequestUri();
447+
String encoding = pageContext.getResponse().getCharacterEncoding();
448+
try {
449+
requestUri = UriUtils.encodePath(requestUri, encoding);
450+
}
451+
catch (UnsupportedEncodingException e) {
452+
throw new JspException(e);
453+
}
445454
ServletResponse response = this.pageContext.getResponse();
446455
if (response instanceof HttpServletResponse) {
447456
requestUri = ((HttpServletResponse) response).encodeURL(requestUri);

spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/FormTagTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -340,6 +340,21 @@ public void testRequestDataValueProcessorHooks() throws Exception {
340340
assertFormTagClosed(output);
341341
}
342342

343+
public void testDefaultActionEncoded() throws Exception {
344+
345+
this.request.setRequestURI("/a b c");
346+
request.setQueryString("");
347+
348+
this.tag.doStartTag();
349+
this.tag.doEndTag();
350+
this.tag.doFinally();
351+
352+
String output = getOutput();
353+
String formOutput = getFormTag(output);
354+
355+
assertContainsAttribute(formOutput, "action", "/a%20b%20c");
356+
}
357+
343358
private String getFormTag(String output) {
344359
int inputStart = output.indexOf("<", 1);
345360
int inputEnd = output.lastIndexOf(">", output.length() - 2);

0 commit comments

Comments
 (0)