snoopdave commented on code in PR #357:
URL: https://github.com/apache/roller/pull/357#discussion_r4636773448


##########
app/src/main/java/org/apache/roller/weblogger/util/Bannedwordslist.java:
##########
@@ -440,9 +479,93 @@ public static void populateSpamRules(
             } else {
                 stringRules.add(token);
             }
-        }        
+        }
     }
-        
+
+    /**
+     * The literal text, case-insensitive, with a word boundary on each end
+     * that is a word character; {@code \b} next to "(" or "/" would need a
+     * word character beside it and so would rarely match.
+     */
+    private static Pattern wordPattern(String word) {
+        StringBuilder regex = new StringBuilder();
+        if (isWordChar(word.charAt(0))) {
+            regex.append("\\b");
+        }
+        regex.append(Pattern.quote(word));
+        if (isWordChar(word.charAt(word.length() - 1))) {
+            regex.append("\\b");
+        }
+        return Pattern.compile(regex.toString(), Pattern.CASE_INSENSITIVE);
+    }
+
+    private static boolean isWordChar(char c) {
+        return c == '_' || (c < 128 && Character.isLetterOrDigit(c));

Review Comment:
   **Important:** In plain-word mode, `isWordChar('é')` is false, so a `café` 
rule also matches `caféine`. `CASE_INSENSITIVE` alone also misses `CAFÉ`. Use 
Unicode-aware case folding and word-boundary checks, and add tests for both 
cases.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to