Skip to content

Commit b843719

Browse files
chaoliu719twaugh
authored andcommitted
fix: Add CRLF support in patch header filename parsing
Fix the filename parsing from patch headers to properly handle CRLF line endings. Previously, the code only checked for '\n' as line ending, which caused incorrect parsing when processing patches with Windows-style CRLF line endings. This fixes issues where filenames in patches with CRLF line endings were not being correctly extracted, particularly affecting Windows-generated patch files. Signed-off-by: Liu Chao <chaoliu719@gmail.com>
1 parent 27ced74 commit b843719

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎src/diff.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ read_timestamp (const char *timestamp, struct tm *result, long *zone)
10921092
char *
10931093
filename_from_header (const char *header)
10941094
{
1095-
int first_space = strcspn (header, " \t\n");
1095+
int first_space = strcspn (header, " \t\n\r");
10961096
int h = first_space;
10971097
while (header[h] == ' ') {
10981098
int i;
@@ -1102,10 +1102,10 @@ filename_from_header (const char *header)
11021102
if (!read_timestamp (header + h + i, NULL, NULL))
11031103
break;
11041104
h += i + 1;
1105-
h += strcspn (header + h, " \t\n");
1105+
h += strcspn (header + h, " \t\n\r");
11061106
}
11071107

1108-
if (header[h] == '\n' && h > first_space)
1108+
if ((header[h] == '\n' || header[h] == '\r') && h > first_space)
11091109
/* If we couldn't see a date we recognized, but did see
11101110
at least one space, split at the first. */
11111111
h = first_space;

0 commit comments

Comments
 (0)