Skip to content

Commit

Permalink
ListManager: Catch invalid BES regex patterns and log them
Browse files Browse the repository at this point in the history
Fixes #28
  • Loading branch information
Krinkle committed Oct 13, 2017
1 parent 22861dd commit a55e212
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/CVNBot/ListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,23 @@ public listMatch isWatchedArticle(string title, string project)
return lm;
}

public bool matchesPattern(string input, string pattern) {
listMatch lm = new listMatch();
try
{
if (Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase))
{
return true;
}
} catch (Exception ex)
{
logger.Warn("Found invalid pattern: " + pattern, ex);
Program.BroadcastDD("ERROR", "LMGNR_REGEX", ex.Message, input);
}

return false;
}

public listMatch matchesList(string title, int list)
{
listMatch lm = new listMatch();
Expand All @@ -784,7 +801,7 @@ public listMatch matchesList(string title, int list)
IDataReader idr = cmd.ExecuteReader();
while (idr.Read())
{
if (Regex.IsMatch(title, idr.GetString(0), RegexOptions.IgnoreCase))
if (matchesPattern(title, idr.GetString(0)))
{
lm.Success = true;
lm.matchedItem = idr.GetString(0);
Expand Down

0 comments on commit a55e212

Please sign in to comment.