Add DebugLog message for bad pattern in rx operator

This commit is contained in:
Martin Vierula
2022-04-21 11:16:01 -07:00
parent ced56c5b08
commit 1aa7616c18
5 changed files with 54 additions and 0 deletions

View File

@@ -52,6 +52,10 @@ bool Rx::evaluate(Transaction *transaction, RuleWithActions *rule,
}
std::vector<Utils::SMatchCapture> captures;
if (re->hasError()) {
ms_dbg_a(transaction, 3, "Error with regular expression: \"" + re->pattern + "\"");
return false;
}
re->searchOneMatch(input, captures);
if (rule && rule->hasCaptureAction() && transaction) {

View File

@@ -75,6 +75,9 @@ Regex::Regex(const std::string& pattern_, bool ignoreCase)
pcre2_options, &errornumber, &erroroffset, NULL);
if (m_pc != NULL) {
m_match_data = pcre2_match_data_create_from_pattern(m_pc, NULL);
if (m_match_data == NULL) {
m_pc = NULL;
}
}
#else
const char *errptr = NULL;

View File

@@ -72,6 +72,9 @@ class Regex {
Regex(const Regex&) = delete;
Regex& operator=(const Regex&) = delete;
bool hasError() const {
return (m_pc == NULL);
}
std::list<SMatch> searchAll(const std::string& s) const;
bool searchOneMatch(const std::string& s, std::vector<SMatchCapture>& captures) const;
bool searchGlobal(const std::string& s, std::vector<SMatchCapture>& captures) const;