From 26cef61d7f3884497dd6c2e164397c6b70464b1b Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Sat, 3 Oct 2015 20:25:56 -0700 Subject: [PATCH] Fixed empty banned words list muting all chat. --- src/me/ryanhamshire/GriefPrevention/Tests.java | 8 ++++++++ src/me/ryanhamshire/GriefPrevention/WordFinder.java | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/me/ryanhamshire/GriefPrevention/Tests.java b/src/me/ryanhamshire/GriefPrevention/Tests.java index dc52ff9..68f295f 100644 --- a/src/me/ryanhamshire/GriefPrevention/Tests.java +++ b/src/me/ryanhamshire/GriefPrevention/Tests.java @@ -2,6 +2,7 @@ package me.ryanhamshire.GriefPrevention; import static org.junit.Assert.*; +import java.util.ArrayList; import java.util.Arrays; import org.junit.Test; @@ -57,4 +58,11 @@ public class Tests WordFinder finder = new WordFinder(Arrays.asList("alpha")); assertFalse(finder.hasMatch("Unit testing is smart.")); } + + @Test + public void WordFinder_EmptyList() + { + WordFinder finder = new WordFinder(new ArrayList()); + assertFalse(finder.hasMatch("alpha")); + } } \ No newline at end of file diff --git a/src/me/ryanhamshire/GriefPrevention/WordFinder.java b/src/me/ryanhamshire/GriefPrevention/WordFinder.java index 7c3191e..4d2cb78 100644 --- a/src/me/ryanhamshire/GriefPrevention/WordFinder.java +++ b/src/me/ryanhamshire/GriefPrevention/WordFinder.java @@ -10,6 +10,8 @@ class WordFinder WordFinder(List wordsToFind) { + if(wordsToFind.size() == 0) return; + StringBuilder patternBuilder = new StringBuilder(); for(String word : wordsToFind) { @@ -28,6 +30,8 @@ class WordFinder boolean hasMatch(String input) { + if(this.pattern == null) return false; + Matcher matcher = this.pattern.matcher(input); return matcher.find(); }