Skip to content

Commit a760302

Browse files
asterite3Felipe Zimmerle
authored and
Felipe Zimmerle
committed
support macro expansion in @rx
try to use macro expansion on @rx argument before matching. If after expansion argument changed, make new Regex from the macro-expanded argument and use that for matching. Fixes #1528
1 parent 210e72a commit a760302

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/operators/rx.cc

+12-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule,
3333
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
3434
SMatch match;
3535
std::list<SMatch> matches;
36+
Regex * re = m_re;
3637

3738
if (m_param.empty()) {
3839
return true;
3940
}
4041

41-
matches = m_re->searchAll(input);
42+
std::string eparam = MacroExpansion::expand(m_param, transaction);
43+
44+
if (eparam != m_param) {
45+
re = new Regex(eparam);
46+
}
47+
48+
matches = re->searchAll(input);
4249
if (rule && rule->getActionsByName("capture").size() > 0 && transaction) {
4350
int i = 0;
4451
matches.reverse();
@@ -58,6 +65,10 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule,
5865
logOffset(ruleMessage, i.m_offset, i.m_length);
5966
}
6067

68+
if (re != m_re) {
69+
delete re;
70+
}
71+
6172
if (matches.size() > 0) {
6273
return true;
6374
}

0 commit comments

Comments
 (0)