glob patterns: wildcards also match path separators (like before)

This commit is contained in:
Daniel Marjamäki 2018-04-09 18:59:18 +02:00
parent 8734e4dd38
commit e6114a2321
2 changed files with 4 additions and 4 deletions

View File

@ -278,17 +278,17 @@ bool Suppressions::matchglob(const std::string &pattern, const std::string &name
switch (*p) { switch (*p) {
case '*': case '*':
// Step forward until we match the next character after * // Step forward until we match the next character after *
while (*n != '\0' && *n != p[1] && *n != '\\' && *n != '/') { while (*n != '\0' && *n != p[1]) {
n++; n++;
} }
if (*n != '\0' && *n != '/') { if (*n != '\0') {
// If this isn't the last possibility, save it for later // If this isn't the last possibility, save it for later
backtrack.push(std::make_pair(p, n)); backtrack.push(std::make_pair(p, n));
} }
break; break;
case '?': case '?':
// Any character matches unless we're at the end of the name // Any character matches unless we're at the end of the name
if (*n != '\0' && *n != '\\' && *n != '/') { if (*n != '\0') {
n++; n++;
} else { } else {
matching = false; matching = false;

View File

@ -514,7 +514,7 @@ private:
ASSERT_EQUALS(true, Suppressions::matchglob("*y*", "xyz")); ASSERT_EQUALS(true, Suppressions::matchglob("*y*", "xyz"));
ASSERT_EQUALS(true, Suppressions::matchglob("*y*", "yz")); ASSERT_EQUALS(true, Suppressions::matchglob("*y*", "yz"));
ASSERT_EQUALS(false, Suppressions::matchglob("*y*", "abc")); ASSERT_EQUALS(false, Suppressions::matchglob("*y*", "abc"));
ASSERT_EQUALS(false, Suppressions::matchglob("*", "x/y/z")); ASSERT_EQUALS(true, Suppressions::matchglob("*", "x/y/z"));
ASSERT_EQUALS(true, Suppressions::matchglob("*/y/z", "x/y/z")); ASSERT_EQUALS(true, Suppressions::matchglob("*/y/z", "x/y/z"));
ASSERT_EQUALS(false, Suppressions::matchglob("?", "xyz")); ASSERT_EQUALS(false, Suppressions::matchglob("?", "xyz"));