View | Details | Raw Unified | Return to bug 245690 | Differences between
and this patch

Collapse All | Expand All

(-)files/patch-src_regexstr.cpp (+36 lines)
Line 0 Link Here
1
--- src/regexstr.cpp.orig	2020-04-09 18:02:12 UTC
2
+++ src/regexstr.cpp
3
@@ -11,10 +11,16 @@ RegexStr RegexStr::fromStr(const std::st
4
 {
5
     RegexStr r;
6
     r.source_ = source;
7
-    try {
8
-        r.regex_ = std::regex(source, std::regex::extended);
9
-    }  catch (const std::exception& e) {
10
-        throw std::invalid_argument(e.what());
11
+    // An empty regex is not allowed in the POSIX grammar
12
+    // as one can infer from the grammar at
13
+    // https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_05_03
14
+    // => So we must not compile "" to a regex
15
+    if (!source.empty()) {
16
+        try {
17
+            r.regex_ = std::regex(source, std::regex::extended);
18
+        }  catch (const std::exception& e) {
19
+            throw std::invalid_argument(e.what());
20
+        }
21
     }
22
     return r;
23
 }
24
@@ -26,7 +32,11 @@ bool RegexStr::operator==(const RegexStr
25
 
26
 bool RegexStr::matches(const std::string& str) const
27
 {
28
-    return std::regex_match(str, regex_);
29
+    if (source_.empty()) {
30
+        return false;
31
+    } else {
32
+        return std::regex_match(str, regex_);
33
+    }
34
 }
35
 
36
 template<> RegexStr Converter<RegexStr>::parse(const std::string& source) {

Return to bug 245690