Skip to content

Commit f18595f

Browse files
committed
Makes regular expression selection on collections key case insensitive
This issue was initially reported by @michaelgranzow-avi on #2296. @airween made an initial attempt to provide a fixed at #2107; As a consequence of the pull request review - provided by @victorhora, @zimmerle, and @michaelgranzow-avi - @airween made a second attempt at #2297. After reviewing by @martinhsv, @zimmerle, I have absorbed the essential pieces from @airween patch into this one. This patch differs from @airween's because @airween's patches were partially working: Key exclusions with regex weren't covered, same for anchored variables (e.g. ARGS). During the review, I have highlighted the importance of having elementary test cases. A simple test case on ARGS could spot the issue. Since that is an important fix, I don't want to hold this for one more review cycle; therefore, I am committing the fix myself. Thank you all involved in the solution of this very own issue.
1 parent 560f812 commit f18595f

File tree

8 files changed

+449
-8
lines changed

8 files changed

+449
-8
lines changed

CHANGES

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
v3.x.y - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Regex key selection should not be case-sensitive
5+
[Issue #2296, #2107, #2297 - @michaelgranzow-avi, @victorhora,
6+
@airween, @martinhsv, @zimmerle]
47
- Fix: Only delete Multipart tmp files after rules have run
58
[Issue #2427 - @martinhsv]
69
- Fixed MatchedVar on chained rules

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ TESTS+=test/test-cases/regression/issue-2111.json
160160
TESTS+=test/test-cases/regression/issue-2196.json
161161
TESTS+=test/test-cases/regression/issue-2423-msg-in-chain.json
162162
TESTS+=test/test-cases/regression/issue-2427.json
163+
TESTS+=test/test-cases/regression/issue-2296.json
163164
TESTS+=test/test-cases/regression/issue-394.json
164165
TESTS+=test/test-cases/regression/issue-849.json
165166
TESTS+=test/test-cases/regression/issue-960.json

src/collection/backend/in_memory-per_process.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void InMemoryPerProcess::resolveRegularExpression(const std::string& var,
134134
//std::string name = std::string(var, var.find(":") + 2,
135135
// var.size() - var.find(":") - 3);
136136
//size_t keySize = col.size();
137-
Utils::Regex r(var);
137+
Utils::Regex r(var, true);
138138

139139
for (const auto& x : *this) {
140140
//if (x.first.size() <= keySize + 1) {

src/collection/backend/lmdb.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ void LMDB::resolveRegularExpression(const std::string& var,
537537
MDB_stat mst;
538538
MDB_cursor *cursor;
539539

540-
Utils::Regex r(var);
540+
Utils::Regex r(var, true);
541541

542542
rc = mdb_txn_begin(m_env, NULL, 0, &txn);
543543
lmdb_debug(rc, "txn", "resolveRegularExpression");

src/utils/regex.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ bool crlfIsNewline() {
5252
return crlf_is_newline;
5353
}
5454

55-
Regex::Regex(const std::string& pattern_)
55+
Regex::Regex(const std::string& pattern_, bool ignoreCase)
5656
: pattern(pattern_.empty() ? ".*" : pattern_) {
5757
const char *errptr = NULL;
5858
int erroffset;
59+
int flags = (PCRE_DOTALL|PCRE_MULTILINE);
5960

60-
m_pc = pcre_compile(pattern.c_str(), PCRE_DOTALL|PCRE_MULTILINE,
61+
if (ignoreCase == true) {
62+
flags |= PCRE_CASELESS;
63+
}
64+
m_pc = pcre_compile(pattern.c_str(), flags,
6165
&errptr, &erroffset, NULL);
6266

6367
m_pce = pcre_study(m_pc, pcre_study_opt, &errptr);

src/utils/regex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct SMatchCapture {
6161

6262
class Regex {
6363
public:
64-
explicit Regex(const std::string& pattern_);
64+
explicit Regex(const std::string& pattern_, bool ignoreCase = false);
6565
~Regex();
6666

6767
// m_pc and m_pce can't be easily copied

src/variables/variable.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ class KeyExclusion {
116116
class KeyExclusionRegex : public KeyExclusion {
117117
public:
118118
explicit KeyExclusionRegex(const Utils::Regex &re)
119-
: m_re(re.pattern) { }
119+
: m_re(re.pattern, true) { }
120120
explicit KeyExclusionRegex(const std::string &re)
121-
: m_re(re) { }
121+
: m_re(re, true) { }
122122

123123
~KeyExclusionRegex() override { }
124124

@@ -595,7 +595,7 @@ class VariableDictElement : public Variable {
595595
class VariableRegex : public Variable {
596596
public:
597597
VariableRegex(const std::string &name, const std::string &regex)
598-
: m_r(regex),
598+
: m_r(regex, true),
599599
m_regex(regex),
600600
Variable(name + ":" + "regex(" + regex + ")") { }
601601

0 commit comments

Comments
 (0)