Skip to content

Commit 3a078de

Browse files
pcloudsgitster
authored andcommitted
wildmatch: fix "**" special case
"**" is adjusted to only be effective when surrounded by slashes, in 40bbee0 (wildmatch: adjust "**" behavior - 2012-10-15). Except that the commit did it wrong: 1. when it checks for "the preceding slash unless ** is at the beginning", it compares to wrong pointer. It should have compared to the beginning of the pattern, not the text. 2. prev_p points to the character before "**", not the first "*". The correct comparison must be "prev_p < pattern" or "prev_p + 1 == pattern", not "prev_p == pattern". 3. The pattern must be surrounded by slashes unless it's at the beginning or the end of the pattern. We do two checks: one for the preceding slash and one the trailing slash. Both checks must be met. The use of "||" is wrong. This patch fixes all above. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d5d80e1 commit 3a078de

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

t/t3070-wildmatch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ match 0 0 'deep/foo/bar/baz/' '**/bar/*'
8383
match 1 0 'deep/foo/bar/baz/' '**/bar/**'
8484
match 0 0 'deep/foo/bar' '**/bar/*'
8585
match 1 0 'deep/foo/bar/' '**/bar/**'
86-
match 1 0 'foo/bar/baz' '**/bar**'
86+
match 0 0 'foo/bar/baz' '**/bar**'
8787
match 1 0 'foo/bar/baz/x' '*/bar/**'
8888
match 0 0 'deep/foo/bar/baz/x' '*/bar/**'
8989
match 1 0 'deep/foo/bar/baz/x' '**/bar/*/*'

wildmatch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ typedef unsigned char uchar;
5858
static int dowild(const uchar *p, const uchar *text, int force_lower_case)
5959
{
6060
uchar p_ch;
61+
const uchar *pattern = p;
6162

6263
for ( ; (p_ch = *p) != '\0'; text++, p++) {
6364
int matched, special;
@@ -87,7 +88,7 @@ static int dowild(const uchar *p, const uchar *text, int force_lower_case)
8788
if (*++p == '*') {
8889
const uchar *prev_p = p - 2;
8990
while (*++p == '*') {}
90-
if ((prev_p == text || *prev_p == '/') ||
91+
if ((prev_p < pattern || *prev_p == '/') &&
9192
(*p == '\0' || *p == '/' ||
9293
(p[0] == '\\' && p[1] == '/'))) {
9394
/*

0 commit comments

Comments
 (0)