Przeglądaj źródła

fix #1349 remove @Required on replacement

Shinsuke Sugaya 7 lat temu
rodzic
commit
dff03970bb

+ 0 - 1
src/main/java/org/codelibs/fess/app/web/admin/pathmap/CreateForm.java

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

+ 10 - 3
src/main/java/org/codelibs/fess/helper/PathMappingHelper.java

@@ -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);
                 }
             }
         }