Enable usage of relative urls by prepending referer on relative paths
nclazz/nclazz-mail-relay/pipeline/head This commit looks good Details
nclazz/nclazz-mail-relay/pipeline/pr-master This commit looks good Details

pull/21/head
Niclas Thobaben 2022-02-25 15:55:38 +01:00
parent 74f4e9b2d8
commit dd23dfca8e
1 changed files with 9 additions and 2 deletions

View File

@ -47,7 +47,7 @@ public class MessageFormController {
redirect = form.getOnSuccess();
}
return "redirect:" + redirect;
return "redirect:" + addRefererToRelativeUrl(referer, redirect);
}
private String formatErrorRedirect(String referer, MessageForm form, BindingResult bindingResult) {
@ -58,7 +58,14 @@ public class MessageFormController {
.collect(Collectors.joining("&"));
String origin = form.getOnError() != null ? form.getOnError() : referer;
return origin + "?" + queryParams;
return addRefererToRelativeUrl(referer, origin) + "?" + queryParams;
}
private String addRefererToRelativeUrl(String referer, String url) {
if(!url.startsWith("/")) {
return url;
}
return referer + url;
}
private static String mapValidationErrorToQueryParam(ValidationError error) {