diff options
-rw-r--r-- | src/attr_file.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/attr_file.c b/src/attr_file.c index ddd44703a..aef3e64af 100644 --- a/src/attr_file.c +++ b/src/attr_file.c @@ -583,8 +583,11 @@ int git_attr_fnmatch__parse( pattern = *base; - while (git__isspace(*pattern)) pattern++; - if (!*pattern || *pattern == '#') { + while (!allow_space && git__isspace(*pattern)) + pattern++; + + if (!*pattern || *pattern == '#' || *pattern == '\n' || + (*pattern == '\r' && *(pattern + 1) == '\n')) { *base = git__next_line(pattern); return GIT_ENOTFOUND; } @@ -606,8 +609,12 @@ int git_attr_fnmatch__parse( slash_count = 0; for (scan = pattern; *scan != '\0'; ++scan) { - /* scan until (non-escaped) white space */ - if (git__isspace(*scan) && *(scan - 1) != '\\') { + /* + * Scan until a non-escaped whitespace: find a whitespace, then look + * one char backward to ensure that it's not prefixed by a `\`. + * Only look backward if we're not at the first position (`pattern`). + */ + if (git__isspace(*scan) && scan > pattern && *(scan - 1) != '\\') { if (!allow_space || (*scan != ' ' && *scan != '\t' && *scan != '\r')) break; } |