fix #1349 remove @Required on replacement

This commit is contained in:
Shinsuke Sugaya 2017-11-17 23:03:04 +09:00
parent 56cb07ffa9
commit dff03970bb
2 changed files with 10 additions and 4 deletions

View file

@ -38,7 +38,6 @@ public class CreateForm {
@Size(max = 1000)
public String regex;
@Required
@Size(max = 1000)
public String replacement;

View file

@ -105,8 +105,11 @@ public class PathMappingHelper {
String result = text;
for (final PathMapping pathMapping : cachedPathMappingList) {
if (matchUserAgent(pathMapping)) {
result =
result.replaceAll("(\"[^\"]*)" + pathMapping.getRegex() + "([^\"]*\")", "$1" + pathMapping.getReplacement() + "$2");
String replacement = pathMapping.getReplacement();
if (replacement == null) {
replacement = StringUtil.EMPTY;
}
result = result.replaceAll("(\"[^\"]*)" + pathMapping.getRegex() + "([^\"]*\")", "$1" + replacement + "$2");
}
}
return result;
@ -129,7 +132,11 @@ public class PathMappingHelper {
if (matchUserAgent(pathMapping)) {
final Matcher matcher = pathMapping.getMatcher(newUrl);
if (matcher.find()) {
newUrl = matcher.replaceAll(pathMapping.getReplacement());
String replacement = pathMapping.getReplacement();
if (replacement == null) {
replacement = StringUtil.EMPTY;
}
newUrl = matcher.replaceAll(replacement);
}
}
}