sparse-checkout: escape all glob characters on write

The sparse-checkout patterns allow special globs according to
fnmatch(3). When writing cone-mode patterns for paths containing
these characters, they must be escaped.

Use is_glob_special() to check which characters must be escaped
this way, and add a path to the tests that contains all glob
characters at once. Note that ']' is not special, since the
initial bracket '[' is escaped.

Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Derrick Stolee
2020-01-31 20:16:13 +00:00
committed by Junio C Hamano
parent e55682ea26
commit e53ffe2704
2 changed files with 9 additions and 6 deletions

View File

@ -149,7 +149,7 @@ static char *escaped_pattern(char *pattern)
struct strbuf final = STRBUF_INIT;
while (*p) {
if (*p == '*' || *p == '\\')
if (is_glob_special(*p))
strbuf_addch(&final, '\\');
strbuf_addch(&final, *p);