From 647019a804947c02d9d08c4015105b440e0484d8 Mon Sep 17 00:00:00 2001 From: Alexey Zelkin Date: Thu, 16 Jun 2016 13:49:17 +0000 Subject: [PATCH] Use internal PCRE based implementation of regular expressions instead of std C++ regex library. C++ regex library proven to be unusable for gcc 4.8 and earlier version, so reimplement code using PCRE library in order to build workable version of unit_test executable for CentOS 7, RHEL 7, Ubuntu 14 and SUSE Linux 12. --- src/utils/regex.h | 1 + test/unit/unit_test.cc | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/utils/regex.h b/src/utils/regex.h index 536fd461..3f119620 100644 --- a/src/utils/regex.h +++ b/src/utils/regex.h @@ -43,6 +43,7 @@ class SMatch { public: SMatch() : size_(0) { } size_t size() { return size_; } + std::string str() { return match; } int size_; std::string match; }; diff --git a/test/unit/unit_test.cc b/test/unit/unit_test.cc index 9cdcaf82..5bb7d85b 100644 --- a/test/unit/unit_test.cc +++ b/test/unit/unit_test.cc @@ -21,11 +21,11 @@ #include #include #include -#include #include #include "common/colors.h" #include "src/utils.h" +#include "src/utils/regex.h" namespace modsecurity_test { @@ -44,7 +44,6 @@ std::string string_to_hex(const std::string& input) { return output; } - void replaceAll(std::string *s, const std::string &search, const char replace) { for (size_t pos = 0; ; pos += 0) { @@ -59,18 +58,19 @@ void replaceAll(std::string *s, const std::string &search, void json2bin(std::string *str) { - std::regex re("\\\\x([a-z0-9A-Z]{2})"); - std::regex re2("\\\\u([a-z0-9A-Z]{4})"); - std::smatch match; + modsecurity::Utils::Regex re("\\\\x([a-z0-9A-Z]{2})"); + modsecurity::Utils::Regex re2("\\\\u([a-z0-9A-Z]{4})"); + modsecurity::Utils::SMatch match; - while (std::regex_search(*str, match, re) && match.size() > 1) { + while (modsecurity::Utils::regex_search(*str, &match, re) && match.size() > 0) { unsigned int p; std::string toBeReplaced = match.str(); toBeReplaced.erase(0, 2); sscanf(toBeReplaced.c_str(), "%x", &p); replaceAll(str, match.str(), p); } - while (std::regex_search(*str, match, re2) && match.size() > 1) { + + while (modsecurity::Utils::regex_search(*str, &match, re2) && match.size() > 0) { unsigned int p; std::string toBeReplaced = match.str(); toBeReplaced.erase(0, 2);