SPR-9016 Add flag to Redirectview to disable expanding URI vars

This commit is contained in:
Rossen Stoyanchev 2012-01-30 18:39:20 -05:00
parent 610fa618aa
commit 21966990c8
3 changed files with 27 additions and 1 deletions

View File

@ -27,6 +27,7 @@ Changes in version 3.1.1 (2012-02-06)
* allow adding flash attributes in methods with a ModelAndView return value
* preserve quotes in MediaType parameters
* make flash attributes available in the model of ParameterizableViewController and UrlFilenameViewController
* add property to RedirectView to disable expanding URI variables in redirect URL
Changes in version 3.1 GA (2011-12-12)
--------------------------------------

View File

@ -106,6 +106,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
private HttpStatus statusCode;
private boolean expandUriTemplateVariables = true;
/**
* Constructor for use as a bean.
@ -225,6 +226,18 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
this.statusCode = statusCode;
}
/**
* Whether to treat the redirect URL as a URI template.
* Set this flag to <code>false</code> if the redirect URL contains open
* and close curly braces "{", "}" and you don't want them interpreted
* as URI variables.
* <p>Defaults to <code>true</code>.
* @param expandUriTemplateVariables
*/
public void setExpandUriTemplateVariables(boolean expandUriTemplateVariables) {
this.expandUriTemplateVariables = expandUriTemplateVariables;
}
/**
* Returns "true" indicating this view performs a redirect.
*/
@ -288,7 +301,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
enc = WebUtils.DEFAULT_CHARACTER_ENCODING;
}
if (StringUtils.hasText(targetUrl)) {
if (this.expandUriTemplateVariables && StringUtils.hasText(targetUrl)) {
Map<String, String> variables = getCurrentRequestUriVariables(request);
targetUrl = replaceUriTemplateVariables(targetUrl.toString(), model, variables, enc);
}

View File

@ -122,4 +122,16 @@ public class RedirectViewUriTemplateTests {
assertEquals("", this.response.getRedirectedUrl());
}
// SPR-9016
@Test
public void dontApplyUriVariables() throws Exception {
String url = "/test#{'one','abc'}";
RedirectView redirectView = new RedirectView(url, true);
redirectView.setExpandUriTemplateVariables(false);
redirectView.renderMergedOutputModel(new ModelMap(), this.request, this.response);
assertEquals(url, this.response.getRedirectedUrl());
}
}