filter comment or blank line for pmFromFile operator

This commit is contained in:
toubley 2018-12-29 18:02:48 +08:00 committed by Felipe Zimmerle
parent ea7cacf289
commit 7b1b00b5e1
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
2 changed files with 22 additions and 1 deletions

View File

@ -25,6 +25,23 @@
namespace modsecurity {
namespace operators {
bool PmFromFile::isComment(const std::string &s) {
if (s.size() == 0) {
return true;
}
size_t pos = s.find("#");
if (pos != std::string::npos) {
for (int i = 0; i < pos; i++) {
if (!std::isspace(s[i])) {
return false;
}
}
} else {
return false;
}
return true;
}
bool PmFromFile::init(const std::string &config, std::string *error) {
std::istream *iss;
@ -50,7 +67,9 @@ bool PmFromFile::init(const std::string &config, std::string *error) {
}
for (std::string line; std::getline(*iss, line); ) {
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
if (isComment(line) == false) {
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
}
}
while (m_p->is_failtree_done == 0) {

View File

@ -36,6 +36,8 @@ class PmFromFile : public Pm {
: Pm(n, std::move(param)) { }
bool init(const std::string &file, std::string *error) override;
bool isComment(const std::string &s);
};