Fix WordFinder matching anything with empty BannedWords.txt (#1045)

This commit is contained in:
Adam
2020-10-04 15:24:52 -07:00
committed by GitHub
parent 1237276823
commit 6e42ed0da4
2 changed files with 5 additions and 2 deletions
@@ -27,6 +27,8 @@ class WordFinder
//trim extraneous leading pipe (|)
patternString = patternString.substring(1);
}
// No words are defined, match nothing.
else return;
this.pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
}
@@ -2,7 +2,6 @@ package me.ryanhamshire.GriefPrevention;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.UUID;
@@ -68,8 +67,10 @@ public class Tests
@Test
public void testWordFinderEmptyList()
{
WordFinder finder = new WordFinder(new ArrayList<>());
WordFinder finder = new WordFinder(Collections.emptyList());
assertFalse(finder.hasMatch("alpha"));
finder = new WordFinder(Collections.singletonList(""));
assertFalse(finder.hasMatch("beta"));
}
@Test