Commit 63adcc4e by Edward Thomson

attr: optionally treat leading whitespace as significant

When `allow_space` is unset, ensure that leading whitespace is not
skipped.
parent 7d330541
...@@ -583,8 +583,11 @@ int git_attr_fnmatch__parse( ...@@ -583,8 +583,11 @@ int git_attr_fnmatch__parse(
pattern = *base; pattern = *base;
while (git__isspace(*pattern)) pattern++; while (!allow_space && git__isspace(*pattern))
if (!*pattern || *pattern == '#') { pattern++;
if (!*pattern || *pattern == '#' || *pattern == '\n' ||
(*pattern == '\r' && *(pattern + 1) == '\n')) {
*base = git__next_line(pattern); *base = git__next_line(pattern);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
...@@ -606,8 +609,12 @@ int git_attr_fnmatch__parse( ...@@ -606,8 +609,12 @@ int git_attr_fnmatch__parse(
slash_count = 0; slash_count = 0;
for (scan = pattern; *scan != '\0'; ++scan) { 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')) if (!allow_space || (*scan != ' ' && *scan != '\t' && *scan != '\r'))
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment