File tree Expand file tree Collapse file tree 3 files changed +21
-10
lines changed
Expand file tree Collapse file tree 3 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -633,6 +633,11 @@ int git_attr_fnmatch__parse(
633633 if (-- spec -> length == 0 )
634634 return GIT_ENOTFOUND ;
635635
636+ /* Remove trailing spaces. */
637+ while (pattern [spec -> length - 1 ] == ' ' || pattern [spec -> length - 1 ] == '\t' )
638+ if (-- spec -> length == 0 )
639+ return GIT_ENOTFOUND ;
640+
636641 if (pattern [spec -> length - 1 ] == '/' ) {
637642 spec -> length -- ;
638643 spec -> flags = spec -> flags | GIT_ATTR_FNMATCH_DIRECTORY ;
Original file line number Diff line number Diff line change @@ -213,16 +213,6 @@ static int parse_ignore_file(
213213 if (ignore_case )
214214 match -> flags |= GIT_ATTR_FNMATCH_ICASE ;
215215
216- while (match -> length > 0 ) {
217- if (match -> pattern [match -> length - 1 ] == ' ' ||
218- match -> pattern [match -> length - 1 ] == '\t' ) {
219- match -> pattern [match -> length - 1 ] = 0 ;
220- match -> length -- ;
221- } else {
222- break ;
223- }
224- }
225-
226216 scan = git__next_line (scan );
227217
228218 /*
Original file line number Diff line number Diff line change @@ -61,6 +61,22 @@ void test_attr_ignore__ignore_space(void)
6161 assert_is_ignored (true, "NewFolder/NewFolder/File.txt" );
6262}
6363
64+ void test_attr_ignore__ignore_dir (void )
65+ {
66+ cl_git_rewritefile ("attr/.gitignore" , "dir/\n" );
67+
68+ assert_is_ignored (true, "dir" );
69+ assert_is_ignored (true, "dir/file" );
70+ }
71+
72+ void test_attr_ignore__ignore_dir_with_trailing_space (void )
73+ {
74+ cl_git_rewritefile ("attr/.gitignore" , "dir/ \n" );
75+
76+ assert_is_ignored (true, "dir" );
77+ assert_is_ignored (true, "dir/file" );
78+ }
79+
6480void test_attr_ignore__ignore_root (void )
6581{
6682 cl_git_rewritefile ("attr/.gitignore" , "/\n\n/NewFolder\n/NewFolder/NewFolder" );
You can’t perform that action at this time.
0 commit comments