diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 4d36143d4..86c4e2f37 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -30,6 +30,7 @@ New features:: Bug fixes:: + * api: fix function string_match with joker in the string if multiple words matched in input string * irc: set notify level to "private" for received WALLOPS Documentation:: diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 4fa39eaf0..a926c7aa3 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -654,6 +654,13 @@ string_match (const char *string, const char *mask, int case_sensitive) free (word); return 0; } + if ((!pos_word[length_word] && !pos_end[0]) + || string_match (pos_word + length_word, pos_end, + case_sensitive)) + { + free (word); + return 1; + } while (1) { pos_word2 = (case_sensitive) ? @@ -662,8 +669,16 @@ string_match (const char *string, const char *mask, int case_sensitive) if (!pos_word2) break; pos_word = pos_word2; + if ((!pos_word[length_word] && !pos_end[0]) + || string_match (pos_word + length_word, pos_end, + case_sensitive)) + { + free (word); + return 1; + } } - ptr_string = pos_word + length_word; + free (word); + return 0; } else { diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index 9ba1714e1..9960424cc 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -571,6 +571,18 @@ TEST(CoreString, Match) LONGS_EQUAL(1, string_match ("aabaa", "aa*", 1)); LONGS_EQUAL(1, string_match ("aabaabaabaa", "aa*", 0)); LONGS_EQUAL(1, string_match ("aabaabaabaa", "aa*", 1)); + LONGS_EQUAL(1, string_match ("script.color.description", "*script.color*", 0)); + LONGS_EQUAL(1, string_match ("script.color.description", "*script.color*", 1)); + LONGS_EQUAL(1, string_match ("script.color.description", "*script.COLOR*", 0)); + LONGS_EQUAL(0, string_match ("script.color.description", "*script.COLOR*", 1)); + LONGS_EQUAL(1, string_match ("script.color.description", "*script*color*", 0)); + LONGS_EQUAL(1, string_match ("script.color.description", "*script*color*", 1)); + LONGS_EQUAL(1, string_match ("script.color.description", "*script*COLOR*", 0)); + LONGS_EQUAL(0, string_match ("script.color.description", "*script*COLOR*", 1)); + LONGS_EQUAL(1, string_match ("script.script.script", "scr*scr*scr*", 0)); + LONGS_EQUAL(1, string_match ("script.script.script", "SCR*SCR*SCR*", 0)); + LONGS_EQUAL(0, string_match ("script.script.script", "SCR*SCR*SCR*", 1)); + LONGS_EQUAL(0, string_match ("script.script.script", "scr*scr*scr*scr*", 0)); } /*