X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fmatch.c;h=826a2867fafceb46bd2e9dbc2b65184e2350b21e;hb=42ff24f2a525d5965e1841b2ebe3ee0f4b918ac6;hp=acbc7a8d7ae247d04dd2edc34537d46dd66d0025;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e;p=debian%2Famanda diff --git a/common-src/match.c b/common-src/match.c index acbc7a8..826a286 100644 --- a/common-src/match.c +++ b/common-src/match.c @@ -280,6 +280,7 @@ glob_to_regex( * * ? -> [^/] * * -> [^/]* + * [...] -> [...] * [!...] -> [^...] * * The following are given a leading backslash to protect them @@ -381,13 +382,14 @@ tar_to_regex( * one expansion. */ len = strlen(glob); - regex = alloc(1 + len * 5 + 1 + 1); + regex = alloc(1 + len * 5 + 5 + 5); /* * Do the conversion: * * ? -> [^/] * * -> .* + * [...] -> [...] * [!...] -> [^...] * * The following are given a leading backslash to protect them @@ -395,13 +397,19 @@ tar_to_regex( * * ( ) { } + . ^ $ | * - * Put a leading ^ and trailing $ around the result. If the last - * non-escaped character is \ leave the $ off to cause a syntax + * The expression must begin and end either at the beginning/end of the string or + * at at a pathname separator. + * + * If the last non-escaped character is \ leave the $ off to cause a syntax * error when the regex is compiled. */ r = regex; + *r++ = '('; *r++ = '^'; + *r++ = '|'; + *r++ = '/'; + *r++ = ')'; last_ch = '\0'; for (ch = *glob++; ch != '\0'; last_ch = ch, ch = *glob++) { if (last_ch == '\\') { @@ -435,7 +443,11 @@ tar_to_regex( } } if (last_ch != '\\') { + *r++ = '('; *r++ = '$'; + *r++ = '|'; + *r++ = '/'; + *r++ = ')'; } *r = '\0'; @@ -782,9 +794,9 @@ match_level( mylevelexp[strlen(levelexp)] = '\0'; } - if(mylevelexp[strlen(mylevelexp)] == '$') { + if(mylevelexp[strlen(mylevelexp)-1] == '$') { match_exact = 1; - mylevelexp[strlen(mylevelexp)] = '\0'; + mylevelexp[strlen(mylevelexp)-1] = '\0'; } else match_exact = 0;