File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -583,8 +583,11 @@ int git_attr_fnmatch__parse(
583583
584584 pattern = * base ;
585585
586- while (git__isspace (* pattern )) pattern ++ ;
587- if (!* pattern || * pattern == '#' ) {
586+ while (!allow_space && git__isspace (* pattern ))
587+ pattern ++ ;
588+
589+ if (!* pattern || * pattern == '#' || * pattern == '\n' ||
590+ (* pattern == '\r' && * (pattern + 1 ) == '\n' )) {
588591 * base = git__next_line (pattern );
589592 return GIT_ENOTFOUND ;
590593 }
@@ -606,8 +609,12 @@ int git_attr_fnmatch__parse(
606609
607610 slash_count = 0 ;
608611 for (scan = pattern ; * scan != '\0' ; ++ scan ) {
609- /* scan until (non-escaped) white space */
610- if (git__isspace (* scan ) && * (scan - 1 ) != '\\' ) {
612+ /*
613+ * Scan until a non-escaped whitespace: find a whitespace, then look
614+ * one char backward to ensure that it's not prefixed by a `\`.
615+ * Only look backward if we're not at the first position (`pattern`).
616+ */
617+ if (git__isspace (* scan ) && scan > pattern && * (scan - 1 ) != '\\' ) {
611618 if (!allow_space || (* scan != ' ' && * scan != '\t' && * scan != '\r' ))
612619 break ;
613620 }
You can’t perform that action at this time.
0 commit comments