Module: check_mk
Branch: master
Commit: e6f4aaa818d065d3ea142884936c39a0708468ca
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e6f4aaa818d065…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Feb 16 14:41:07 2018 +0100
Handle regex fallback, too.
Change-Id: I78309906f4fdbdf0d435c1d144a0a59527ff7e34
---
livestatus/src/RegExp.cc | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/livestatus/src/RegExp.cc b/livestatus/src/RegExp.cc
index d01d005..3d6be85 100644
--- a/livestatus/src/RegExp.cc
+++ b/livestatus/src/RegExp.cc
@@ -71,11 +71,15 @@ private:
#include <regex>
class RegExp::Impl {
public:
- // TODO(sp): Handle Syntax == literal.
Impl(const std::string &str, Case c, Syntax s)
- : _regex(str, c == Case::respect
- ? std::regex::extended
- : std::regex::extended | std::regex::icase) {}
+ : _regex(s == Syntax::literal
+ ? std::regex_replace(
+ str, std::regex(R"([.^$|()\[\]{}*+?\\])"),
+ R"(\&)", std::regex_constants::format_sed)
+ : str,
+ c == Case::respect
+ ? std::regex::extended
+ : std::regex::extended | std::regex::icase) {}
std::string replace(const std::string &str,
const std::string &replacement) {