Skip to content

Commit 27547e5

Browse files
committed
attr: skip UTF8 BOM at the beginning of the input file
Signed-off-by: Junio C Hamano <[email protected]>
1 parent 599446d commit 27547e5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

attr.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "exec_cmd.h"
1313
#include "attr.h"
1414
#include "dir.h"
15+
#include "utf8.h"
1516

1617
const char git_attr__true[] = "(builtin)true";
1718
const char git_attr__false[] = "\0(builtin)false";
@@ -369,8 +370,12 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
369370
return NULL;
370371
}
371372
res = xcalloc(1, sizeof(*res));
372-
while (fgets(buf, sizeof(buf), fp))
373-
handle_attr_line(res, buf, path, ++lineno, macro_ok);
373+
while (fgets(buf, sizeof(buf), fp)) {
374+
char *bufp = buf;
375+
if (!lineno)
376+
skip_utf8_bom(&bufp, strlen(bufp));
377+
handle_attr_line(res, bufp, path, ++lineno, macro_ok);
378+
}
374379
fclose(fp);
375380
return res;
376381
}

0 commit comments

Comments
 (0)