Validate contextPath in RedirectView

Issue: SPR-16752
This commit is contained in:
Rossen Stoyanchev
2018-04-23 15:20:12 -04:00
parent e9a8a5065b
commit de18d96413
2 changed files with 24 additions and 9 deletions

View File

@@ -329,7 +329,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
if (this.contextRelative && getUrl().startsWith("/")) {
// Do not apply context path to relative URLs.
targetUrl.append(request.getContextPath());
targetUrl.append(getContextPath(request));
}
targetUrl.append(getUrl());
@@ -355,6 +355,14 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
return targetUrl.toString();
}
private String getContextPath(HttpServletRequest request) {
String contextPath = request.getContextPath();
while (contextPath.startsWith("//")) {
contextPath = contextPath.substring(1);
}
return contextPath;
}
/**
* Replace URI template variables in the target URL with encoded model
* attributes or URI variables from the current request. Model attributes