Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/collection/backend/in_memory-per_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void InMemoryPerProcess::resolveRegularExpression(const std::string& var,
//std::string name = std::string(var, var.find(":") + 2,
// var.size() - var.find(":") - 3);
//size_t keySize = col.size();
Utils::Regex r(var, PCRE_CASELESS);
Utils::Regex r(var, true);

for (const auto& x : *this) {
//if (x.first.size() <= keySize + 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/collection/backend/lmdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void LMDB::resolveRegularExpression(const std::string& var,
MDB_cursor *cursor;
size_t pos;

Utils::Regex r(var, PCRE_CASELESS);
Utils::Regex r(var, true);

rc = mdb_txn_begin(m_env, NULL, 0, &txn);
lmdb_debug(rc, "txn", "resolveRegularExpression");
Expand Down
19 changes: 5 additions & 14 deletions src/utils/regex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,15 @@ namespace modsecurity {
namespace Utils {


Regex::Regex(const std::string& pattern_)
Regex::Regex(const std::string& pattern_, bool caseSensitive)
: pattern(pattern_.empty() ? ".*" : pattern_) {
const char *errptr = NULL;
int erroffset;
int flags = (PCRE_DOTALL|PCRE_MULTILINE);

m_pc = pcre_compile(pattern.c_str(), PCRE_DOTALL|PCRE_MULTILINE,
&errptr, &erroffset, NULL);

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

Regex::Regex(const std::string& pattern_, int flags)
: pattern(pattern_.empty() ? ".*" : pattern_){
const char *errptr = NULL;
int erroffset;

flags |= (PCRE_DOTALL|PCRE_MULTILINE);

if (caseSensitive == true) {
flags |= PCRE_CASELESS;
}
m_pc = pcre_compile(pattern.c_str(), flags,
&errptr, &erroffset, NULL);

Expand Down
3 changes: 1 addition & 2 deletions src/utils/regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class SMatch {

class Regex {
public:
explicit Regex(const std::string& pattern_);
explicit Regex(const std::string& pattern_, int flags);
explicit Regex(const std::string& pattern_, bool caseSensitive = false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may not need this to be explicit anylonger.

~Regex();

// m_pc and m_pce can't be easily copied
Expand Down