Skip to content

Commit 8040904

Browse files
committed
Removed pcre dependency from outside of regex class
1 parent ea937cf commit 8040904

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

src/collection/backend/in_memory-per_process.cc

Lines changed: 1 addition & 1 deletion
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, PCRE_CASELESS);
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ void LMDB::resolveRegularExpression(const std::string& var,
538538
MDB_cursor *cursor;
539539
size_t pos;
540540

541-
Utils::Regex r(var, PCRE_CASELESS);
541+
Utils::Regex r(var, true);
542542

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

src/utils/regex.cc

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,15 @@ namespace modsecurity {
3838
namespace Utils {
3939

4040

41-
Regex::Regex(const std::string& pattern_)
41+
Regex::Regex(const std::string& pattern_, bool caseSensitive)
4242
: pattern(pattern_.empty() ? ".*" : pattern_) {
4343
const char *errptr = NULL;
4444
int erroffset;
45+
int flags = (PCRE_DOTALL|PCRE_MULTILINE);
4546

46-
m_pc = pcre_compile(pattern.c_str(), PCRE_DOTALL|PCRE_MULTILINE,
47-
&errptr, &erroffset, NULL);
48-
49-
m_pce = pcre_study(m_pc, pcre_study_opt, &errptr);
50-
}
51-
52-
Regex::Regex(const std::string& pattern_, int flags)
53-
: pattern(pattern_.empty() ? ".*" : pattern_){
54-
const char *errptr = NULL;
55-
int erroffset;
56-
57-
flags |= (PCRE_DOTALL|PCRE_MULTILINE);
58-
47+
if (caseSensitive == true) {
48+
flags |= PCRE_CASELESS;
49+
}
5950
m_pc = pcre_compile(pattern.c_str(), flags,
6051
&errptr, &erroffset, NULL);
6152

src/utils/regex.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ class SMatch {
5050

5151
class Regex {
5252
public:
53-
explicit Regex(const std::string& pattern_);
54-
explicit Regex(const std::string& pattern_, int flags);
53+
explicit Regex(const std::string& pattern_, bool caseSensitive = false);
5554
~Regex();
5655

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

0 commit comments

Comments
 (0)