Skip to content
Permalink
Browse files Browse the repository at this point in the history
Add encoding for the default action in FormTag
Issue: SPR-11426
  • Loading branch information
rstoyanchev committed Feb 13, 2014
1 parent 0cb27f4 commit 741b4b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

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

import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.servlet.ServletRequest;
Expand All @@ -32,6 +33,7 @@
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.support.RequestDataValueProcessor;
import org.springframework.web.util.HtmlUtils;
import org.springframework.web.util.UriUtils;

/**
* Databinding-aware JSP tag for rendering an HTML '{@code form}' whose
Expand Down Expand Up @@ -442,6 +444,13 @@ else if (StringUtils.hasText(servletRelativeAction)) {
}
else {
String requestUri = getRequestContext().getRequestUri();
String encoding = pageContext.getResponse().getCharacterEncoding();
try {
requestUri = UriUtils.encodePath(requestUri, encoding);
}
catch (UnsupportedEncodingException e) {
throw new JspException(e);
}
ServletResponse response = this.pageContext.getResponse();
if (response instanceof HttpServletResponse) {
requestUri = ((HttpServletResponse) response).encodeURL(requestUri);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -340,6 +340,21 @@ public void testRequestDataValueProcessorHooks() throws Exception {
assertFormTagClosed(output);
}

public void testDefaultActionEncoded() throws Exception {

this.request.setRequestURI("/a b c");
request.setQueryString("");

this.tag.doStartTag();
this.tag.doEndTag();
this.tag.doFinally();

String output = getOutput();
String formOutput = getFormTag(output);

assertContainsAttribute(formOutput, "action", "/a%20b%20c");
}

private String getFormTag(String output) {
int inputStart = output.indexOf("<", 1);
int inputEnd = output.lastIndexOf(">", output.length() - 2);
Expand Down

0 comments on commit 741b4b2

Please sign in to comment.