api: fix return of function string_match() when there are multiple masks in the string (issue #812)

Some tests are added as well to test the multiple masks in the string.
v2.8-utf8proc
Sébastien Helleu 2016-10-02 08:58:19 +02:00
parent f98d50ebab
commit 54841f6294
3 changed files with 33 additions and 2 deletions

View File

@ -36,6 +36,7 @@ Improvements::
Bug fixes::
* core, irc, xfer: refresh domain name and name server addresses before connection to servers (fix connection to servers after suspend mode) (issue #771)
* api: fix return of function string_match() when there are multiple masks in the string (issue #812)
* api: fix crash in function network_connect_to() if address is NULL
* api: fix connection to servers with hook_connect() on Windows 10 with Windows subsystem for Linux (issue #770)
* api: fix crash in function string_split_command() when the separator is not a semicolon (issue #731)

View File

@ -378,7 +378,7 @@ string_strcasestr (const char *string, const char *search)
int
string_match (const char *string, const char *mask, int case_sensitive)
{
const char *ptr_string, *ptr_mask, *pos_word, *pos_end;
const char *ptr_string, *ptr_mask, *pos_word, *pos_word2, *pos_end;
char *word;
int wildcard, length_word;
@ -429,7 +429,10 @@ string_match (const char *string, const char *mask, int case_sensitive)
/* check if the word is matching */
if (wildcard)
{
/* search the word anywhere in the string (from current position) */
/*
* search the word anywhere in the string (from current position),
* multiple times if needed
*/
pos_word = (case_sensitive) ?
strstr (ptr_string, word) : string_strcasestr (ptr_string, word);
if (!pos_word)
@ -437,6 +440,15 @@ string_match (const char *string, const char *mask, int case_sensitive)
free (word);
return 0;
}
while (1)
{
pos_word2 = (case_sensitive) ?
strstr (pos_word + length_word, word) :
string_strcasestr (pos_word + length_word, word);
if (!pos_word2)
break;
pos_word = pos_word2;
}
ptr_string = pos_word + length_word;
}
else

View File

@ -322,6 +322,24 @@ TEST(String, Match)
LONGS_EQUAL(1, string_match ("test", "*es*", 1));
LONGS_EQUAL(1, string_match ("test", "*ES*", 0));
LONGS_EQUAL(0, string_match ("test", "*ES*", 1));
LONGS_EQUAL(1, string_match ("TEST", "*es*", 0));
LONGS_EQUAL(0, string_match ("TEST", "*es*", 1));
LONGS_EQUAL(0, string_match ("aaba", "*aa", 0));
LONGS_EQUAL(0, string_match ("aaba", "*aa", 1));
LONGS_EQUAL(1, string_match ("abaa", "*aa", 0));
LONGS_EQUAL(1, string_match ("abaa", "*aa", 1));
LONGS_EQUAL(1, string_match ("aabaa", "*aa", 0));
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(0, string_match ("abaa", "aa*", 0));
LONGS_EQUAL(0, string_match ("abaa", "aa*", 1));
LONGS_EQUAL(1, string_match ("aaba", "aa*", 0));
LONGS_EQUAL(1, string_match ("aaba", "aa*", 1));
LONGS_EQUAL(1, string_match ("aabaa", "aa*", 0));
LONGS_EQUAL(1, string_match ("aabaa", "aa*", 1));
LONGS_EQUAL(1, string_match ("aabaabaabaa", "aa*", 0));
LONGS_EQUAL(1, string_match ("aabaabaabaa", "aa*", 1));
}
/*