From 51768b9f7a582fee2ddd7a45da1fb2946a202cfe Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 15 Aug 2015 11:51:19 +0200 Subject: [PATCH] regex filter: if string is invalid utf-8, ignore it --- src/regex_filter.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/regex_filter.h b/src/regex_filter.h index a4abd1f4..a0bbabcf 100644 --- a/src/regex_filter.h +++ b/src/regex_filter.h @@ -56,13 +56,18 @@ inline Regex make(StringT &&s, boost::regex_constants::syntax_option_type flags) template inline bool search(StringT &&s, const Regex &rx) { - return -# ifdef BOOST_REGEX_ICU - boost::u32regex_search -# else - boost::regex_search -# endif // BOOST_REGEX_ICU - (std::forward(s), rx); + try { + return +# ifdef BOOST_REGEX_ICU + boost::u32regex_search +# else + boost::regex_search +# endif // BOOST_REGEX_ICU + (std::forward(s), rx); + } catch (std::out_of_range &) { + // Invalid UTF-8 sequence, ignore the string. + return false; + } } template