diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/testsuite.cpp | 6 | ||||
-rw-r--r-- | src/wildcard.cpp | 25 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/testsuite.cpp b/src/testsuite.cpp index 502f28fd4..ee3346d9d 100644 --- a/src/testsuite.cpp +++ b/src/testsuite.cpp @@ -116,6 +116,8 @@ bool TestSuite::DoWildTests() WCTEST("foobar", "foo*"); WCTEST("foobar", "*bar"); WCTEST("foobar", "foo??r"); + WCTEST("foobar.test", "fo?bar.*t"); + WCTEST("foobar", "foobar"); WCTESTNOT("foobar", "bazqux"); WCTESTNOT("foobar", "*qux"); @@ -123,6 +125,10 @@ bool TestSuite::DoWildTests() WCTESTNOT("foobar", "baz*"); WCTESTNOT("foobar", "foo???r"); WCTESTNOT("foobar", ""); + WCTESTNOT("", "foobar"); + WCTESTNOT("OperServ", "O"); + WCTESTNOT("O", "OperServ"); + WCTESTNOT("foobar.tst", "fo?bar.*g"); CIDRTEST("brain@1.2.3.4", "*@1.2.0.0/16"); CIDRTEST("brain@1.2.3.4", "*@1.2.3.0/24"); diff --git a/src/wildcard.cpp b/src/wildcard.cpp index ccd2e9ec1..b230ab147 100644 --- a/src/wildcard.cpp +++ b/src/wildcard.cpp @@ -41,18 +41,21 @@ CoreExport bool csmatch(const std::string &str, const std::string &mask) while ((string != str.end()) && (wild != mask.end()) && (*wild != '*')) { if ((*wild != *string) && (*wild != '?')) - return 0; + return false; wild++; string++; } + if (wild == mask.end() && string != str.end()) + return false; + while (string != str.end()) { if (wild != mask.end() && *wild == '*') { if (++wild == mask.end()) - return 1; + return true; mp = wild; cp = string; @@ -95,18 +98,25 @@ CoreExport bool match(const std::string &str, const std::string &mask) while ((string != str.end()) && (wild != mask.end()) && (*wild != '*')) { if ((lowermap[(unsigned char)*wild] != lowermap[(unsigned char)*string]) && (*wild != '?')) - return 0; + return false; wild++; string++; + //printf("Iterate first loop\n"); } + if (wild == mask.end() && string != str.end()) + return false; + while (string != str.end()) { + //printf("outer\n %c", *string); if (wild != mask.end() && *wild == '*') { + + //printf("inner %c\n", *wild); if (++wild == mask.end()) - return 1; + return true; mp = wild; cp = string; @@ -118,8 +128,11 @@ CoreExport bool match(const std::string &str, const std::string &mask) else if ((string != str.end() && wild != mask.end()) && ((lowermap[(unsigned char)*wild] == lowermap[(unsigned char)*string]) || (*wild == '?'))) { - wild++; - string++; + if (wild != mask.end()) + wild++; + + if (string != str.end()) + string++; } else { |