diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2019-05-19 16:27:59 +0200 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2019-05-24 16:16:43 +0200 |
commit | 63adcc4e3436abb163426ee431a6f77c29415b10 (patch) | |
tree | 4d8086ce6ed99191cdd65e6cd6cad6b2d32d3bfc | |
parent | 7d3305417bf01d0d8591c322e0b28423df01e4ce (diff) | |
download | libgit2-63adcc4e3436abb163426ee431a6f77c29415b10.tar.gz |
attr: optionally treat leading whitespace as significant
When `allow_space` is unset, ensure that leading whitespace is not
skipped.
-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; } |