stephenhaunts / ProfanityDetector

This is a simple library for detecting profanities within a text string.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CensorString crashes if there is a trailing space

DavidJBerman opened this issue · comments

var filter = new ProfanityFilter.ProfanityFilter();
var result = filter.CensorString("Test string"); // Test string
result = filter.CensorString("Test with trailing space "); // Throws exception:

This can be fixed by invoking String.Trim on the input string.

Exception thrown:
Value cannot be null.
Parameter name: wordToCheck

Stack Trace
at ProfanityFilter.WhiteList.Contains(String wordToCheck)
at ProfanityFilter.ProfanityFilter.FilterWordListByWhiteList(String[] words)
at ProfanityFilter.ProfanityFilter.CensorString(String sentence, Char censorCharacter)
at ProfanityFilter.ProfanityFilter.CensorString(String sentence)

Hi, thanks for this. I will try and get this resolved this week.

Hi Stephen, any update on this issue? We're trying to use your code and yesterday alone this caused the system to throw and log over 80,000 exceptions. If you don't have time to fix it let us know, we'll have to look for something else. We like your library but it needs testing for more inputs. For example, not only does it throw exception on empty strings, strings that are just spaces, trailing space, it also crashes on other strings that are hard to anticipate it crashing on , like a string with dots and dashes but no spaces.

System.ArgumentNullException: Value cannot be null.
Parameter name: wordToCheck
at ProfanityFilter.WhiteList.Contains(String wordToCheck)
at ProfanityFilter.ProfanityFilter.FilterWordListByWhiteList(String[] words)
at ProfanityFilter.ProfanityFilter.CensorString(String sentence, Char censorCharacter)
at ProfanityFilter.ProfanityFilter.CensorString(String sentence)

It looks like you just need to make sure that the code invoking WhiteList.Contains is only called if !string.IsNullOrEmpty(wordToCheck)

Sorry for the delay. Not been my usual motivated self the past few weeks. I have checked in a fix for this bug. I will push out a new nuget package when I have addressed a few more small bugs.

I have updated the NuGet package to version 0.1.4 so you can make use of this fix.

If you encounter any other edge cases, please open another issue and I will resolve them.

Thanks

Steve