Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ProfanityFilter.Tests.Unit/ProfanityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -898,5 +898,14 @@ public void ContainsProfanityReturnsTrueWhenProfanityIsADollarDollar()

Assert.IsTrue(result);
}

[TestMethod]
public void ContainsProfanityReturnsTrueWhenProfanityIsVariableCase()
{
var filter = new ProfanityFilter();
var result = filter.ContainsProfanity("Fuck");

Assert.IsTrue(result);
}
}
}
4 changes: 2 additions & 2 deletions ProfanityFilter/ProfanityFilter/ProfanityFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ public bool ContainsProfanity(string term)
return false;
}

Regex regex = new Regex(string.Format(@"(?:{0})", string.Join("|", potentialProfanities).Replace("$", "\\$"), RegexOptions.IgnoreCase));
string regexPattern = string.Format(@"(?:{0})", string.Join("|", potentialProfanities).Replace("$", "\\$"));

foreach (Match profanity in regex.Matches(term))
foreach (Match profanity in Regex.Matches(term, regexPattern, RegexOptions.IgnoreCase))
{
// if any matches are found and aren't in the allowed list, we can return true here without checking further
if (!AllowList.Contains(profanity.Value.ToLower(CultureInfo.InvariantCulture)))
Expand Down