Validate contextPath in RedirectView
Issue: SPR-16752
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user