diff --git a/lib/search/glob.c b/lib/search/glob.c index 18e6a7fe1..1486d21d9 100644 --- a/lib/search/glob.c +++ b/lib/search/glob.c @@ -54,25 +54,36 @@ mc_search__glob_translate_to_regex (const GString * astr) buff = g_string_sized_new (32); for (loop = 0; loop < astr->len; loop++) + { switch (str[loop]) { case '*': if (!strutils_is_char_escaped (str, &(str[loop]))) + { g_string_append (buff, inside_group ? ".*" : "(.*)"); + continue; + } break; case '?': if (!strutils_is_char_escaped (str, &(str[loop]))) + { g_string_append (buff, inside_group ? "." : "(.)"); + continue; + } break; case ',': if (!strutils_is_char_escaped (str, &(str[loop]))) - g_string_append_c (buff, '|'); + { + g_string_append_c (buff, inside_group ? '|' : ','); + continue; + } break; case '{': if (!strutils_is_char_escaped (str, &(str[loop]))) { g_string_append_c (buff, '('); inside_group = TRUE; + continue; } break; case '}': @@ -80,6 +91,7 @@ mc_search__glob_translate_to_regex (const GString * astr) { g_string_append_c (buff, ')'); inside_group = FALSE; + continue; } break; case '+': @@ -89,12 +101,12 @@ mc_search__glob_translate_to_regex (const GString * astr) case ')': case '^': g_string_append_c (buff, '\\'); - /* fall through */ + break; default: - g_string_append_c (buff, str[loop]); break; } - + g_string_append_c (buff, str[loop]); + } return buff; } diff --git a/tests/lib/search/glob_translate_to_regex.c b/tests/lib/search/glob_translate_to_regex.c index 84e540999..253586280 100644 --- a/tests/lib/search/glob_translate_to_regex.c +++ b/tests/lib/search/glob_translate_to_regex.c @@ -66,15 +66,15 @@ static const struct test_glob_translate_to_regex_ds }, { "t,e.st", - "t|e\\.st" + "t,e\\.st" }, { "^t,e.+st+$", - "\\^t|e\\.\\+st\\+\\$" + "\\^t,e\\.\\+st\\+\\$" }, { "te!@#$%^&*()_+|\";:'{}:><(.)\\\\\\.|/[]|\\/st" + "te!@#\\$%\\^&(.*)\\(\\)_\\+|\";:'():><(.)\\?\\*\\.,/[]|\\/st" }, }; /* *INDENT-ON* */