{"thread":{"id":"43824","subject":"[PATCH] config.c: Tolerate UTF8 BOM at the beginning of config file","startedAt":"2008-10-01T20:13:02Z","lastAt":"2008-10-01T20:13:02Z","messageCount":1,"participants":["Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"299076","messageId":"1222891982-24193-1-git-send-email-pasky@suse.cz","threadId":"43824","inReplyTo":null,"subject":"[PATCH] config.c: Tolerate UTF8 BOM at the beginning of config file","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2008-10-01T20:13:02Z","receivedAt":"2008-10-01T20:13:02Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Unfortunately, the abomination of Windows Notepad likes to scatted\nnon-sensical UTF8 BOM marks across text files it edits. This is\nespecially troublesome when editing the Git configuration file,\nand it does not appear to be particularly harmful to teach Git\nto deal with this poo in the configfile.\n\nSigned-off-by: Petr Baudis <petr.baudis@novartis.com>\n\n---\n config.c |   19 +++++++++++++++++++\n 1 files changed, 19 insertions(+), 0 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 53f04a0..1d30120 100644\n--- a/config.c\n+++ b/config.c\n@@ -205,8 +205,27 @@ static int git_parse_file(config_fn_t fn, void *data)\n \tint baselen = 0;\n \tstatic char var[MAXNAME];\n \n+\t/* U+FEFF Byte Order Mark in UTF8 */\n+\tstatic const unsigned char *utf8_bom = (unsigned char *) \"\\xef\\xbb\\xbf\";\n+\tconst unsigned char *bomptr = utf8_bom;\n+\n \tfor (;;) {\n \t\tint c = get_next_char();\n+\t\tif (bomptr && *bomptr) {\n+\t\t\t/* We are at the file beginning; skip UTF8-encoded BOM\n+\t\t\t * if present. Sane editors won't put this in on their\n+\t\t\t * own, but e.g. Windows Notepad will do it happily. */\n+\t\t\tif ((unsigned char) c == *bomptr) {\n+\t\t\t\tbomptr++;\n+\t\t\t\tcontinue;\n+\t\t\t} else {\n+\t\t\t\t/* Do not tolerate partial BOM. */\n+\t\t\t\tif (bomptr != utf8_bom)\n+\t\t\t\t\tbreak;\n+\t\t\t\t/* No BOM at file beginning. Cool. */\n+\t\t\t\tbomptr = NULL;\n+\t\t\t}\n+\t\t}\n \t\tif (c == '\\n') {\n \t\t\tif (config_file_eof)\n \t\t\t\treturn 0;\n-- \ntg: (9800c0d..) t/config/utf8-bom (depends on: vanilla/master)\n"}]}