From e2889bfefd41a22f2a5aaa4f613720302dcfe566 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Fri, 14 Sep 2012 00:59:00 +0200 Subject: [PATCH] regex filter: fix assertion fail if regex wasn't properly compiled --- src/regex_filter.h | 2 +- src/regexes.cpp | 5 +++++ src/regexes.h | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/regex_filter.h b/src/regex_filter.h index 38829079..4258a2b1 100644 --- a/src/regex_filter.h +++ b/src/regex_filter.h @@ -35,7 +35,7 @@ template struct RegexFilter bool operator()(const Item &item) { if (m_rx.regex().empty()) return true; - if (!m_rx.error().empty()) + if (!m_rx.compiled() || !m_rx.error().empty()) return false; return m_filter(m_rx, item.value()); } diff --git a/src/regexes.cpp b/src/regexes.cpp index 02ed476c..5b8da962 100644 --- a/src/regexes.cpp +++ b/src/regexes.cpp @@ -52,6 +52,11 @@ const std::string &Regex::error() const return m_error; } +bool Regex::compiled() const +{ + return m_compiled; +} + bool Regex::compile() { if (m_compiled) diff --git a/src/regexes.h b/src/regexes.h index 94ac68ac..66370c2e 100644 --- a/src/regexes.h +++ b/src/regexes.h @@ -37,6 +37,9 @@ struct Regex /// @return compilation error (if there was any) const std::string &error() const; + /// @return true if regular expression is compiled, false otherwise + bool compiled() const; + /// compiles regular expression /// @result true if compilation was successful, false otherwise bool compile();