Przeglądaj źródła

fix #2356 check if pattern exists

Shinsuke Sugaya 5 lat temu
rodzic
commit
ee61a2b778
1 zmienionych plików z 13 dodań i 12 usunięć
  1. 13 12
      src/main/java/org/codelibs/fess/helper/ViewHelper.java

+ 13 - 12
src/main/java/org/codelibs/fess/helper/ViewHelper.java

@@ -216,18 +216,19 @@ public class ViewHelper {
         if (!fessConfig.isResponseHighlightContentTitleEnabled()) {
             return value;
         }
-        return getQuerySet().map(
-                querySet -> {
-                    final Matcher matcher =
-                            Pattern.compile(querySet.stream().map(LaFunctions::h).map(Pattern::quote).collect(Collectors.joining("|")),
-                                    Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(value);
-                    final StringBuffer buf = new StringBuffer(value.length() + 100);
-                    while (matcher.find()) {
-                        matcher.appendReplacement(buf, highlightTagPre + matcher.group(0) + highlightTagPost);
-                    }
-                    matcher.appendTail(buf);
-                    return buf.toString();
-                }).orElse(value);
+        return getQuerySet().map(querySet -> {
+            final String pattern = querySet.stream().map(LaFunctions::h).map(Pattern::quote).collect(Collectors.joining("|"));
+            if (StringUtil.isBlank(pattern)) {
+                return null;
+            }
+            final Matcher matcher = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(value);
+            final StringBuffer buf = new StringBuffer(value.length() + 100);
+            while (matcher.find()) {
+                matcher.appendReplacement(buf, highlightTagPre + matcher.group(0) + highlightTagPost);
+            }
+            matcher.appendTail(buf);
+            return buf.toString();
+        }).orElse(value);
     }
 
     protected OptionalThing<Set<String>> getQuerySet() {