aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/str.cpp15
-rw-r--r--test/common/str.h3
2 files changed, 15 insertions, 3 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 2961a0c61b..4585905d62 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -691,9 +691,18 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod
switch (*pat) {
case '*':
- // Record pattern / string position for backtracking
- p = ++pat;
- q = str;
+ if (*str) {
+ // Record pattern / string position for backtracking
+ p = ++pat;
+ q = str;
+ } else {
+ // If we've reached the end of str, we can't backtrack further
+ // NB: We can't simply check if pat also ended here, because
+ // the pattern might end with any number of *s.
+ ++pat;
+ p = 0;
+ q = 0;
+ }
// If pattern ended with * -> match
if (!*pat)
return true;
diff --git a/test/common/str.h b/test/common/str.h
index e1f2b39578..0dd075f848 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -310,6 +310,9 @@ class StringTestSuite : public CxxTest::TestSuite
TS_ASSERT(Common::matchString("monkey.s01", "monkey.s*1"));
TS_ASSERT(!Common::matchString("monkey.s99", "monkey.s*1"));
TS_ASSERT(Common::matchString("monkey.s101", "monkey.s*1"));
+
+ TS_ASSERT(!Common::String("").matchString("*_"));
+ TS_ASSERT(Common::String("a").matchString("a***"));
}
void test_string_printf() {