Skip to content

Commit 99d2290

Browse files
committed
Fixed FloodCheck not detecting unicode characters
1 parent 75c3515 commit 99d2290

File tree

2 files changed

+30
-1
lines changed
  • api/src/main/java/io/github/_4drian3d/chatregulator/api/checks
  • plugin/src/test/java/io/github/_4drian3d/chatregulator/modules/checks

2 files changed

+30
-1
lines changed

api/src/main/java/io/github/_4drian3d/chatregulator/api/checks/FloodCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public final class FloodCheck implements Check {
2323
.maximumSize(3)
2424
.initialCapacity(1)
2525
.build(length -> Pattern.compile(
26-
"(\\w)\\1{"+length+",}",
26+
"(.)\\1{"+length+",}",
2727
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)
2828
);
2929
private final Pattern pattern;

plugin/src/test/java/io/github/_4drian3d/chatregulator/modules/checks/FloodTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,33 @@ void testTest(String original, String expected) {
5858

5959
assertEquals(expected, result.replaced());
6060
}
61+
62+
@ParameterizedTest
63+
@CsvSource({
64+
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
65+
" ҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉҉ ҉"
66+
})
67+
void illegalCharsFloodTest(String str) {
68+
final FloodCheck check = FloodCheck.builder()
69+
.controlType(ControlType.BLOCK)
70+
.limit(3)
71+
.build();
72+
final CheckResult result = check.check(TestsUtils.dummyPlayer(), str);
73+
assertTrue(result.isDenied());
74+
}
75+
76+
@ParameterizedTest
77+
@CsvSource({
78+
"pls no",
79+
"plsnoplsnoplsnoplsnoplsnoplsnoplsnoplsnoplsno",
80+
"yeahnosequemásponeraquiparaquenolodetecte"
81+
})
82+
void shouldNotDetectTest(String string) {
83+
final FloodCheck check = FloodCheck.builder()
84+
.controlType(ControlType.BLOCK)
85+
.limit(3)
86+
.build();
87+
final CheckResult result = check.check(TestsUtils.dummyPlayer(), string);
88+
assertTrue(result.isAllowed());
89+
}
6190
}

0 commit comments

Comments
 (0)