diff options
author | Petr Baudis <pasky@suse.cz> | 2008-10-01 22:13:02 +0200 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2008-10-02 17:19:03 -0700 |
commit | de056402fd90dbb1dc47756ef7cbcc9d230a5eb8 (patch) | |
tree | 39811b65bf3848c685eb3abfbe5a1a6aa2c3f078 /config.c | |
parent | 25dfd171d646c38f9344d8e3d8ae0fdf179dd281 (diff) | |
download | git-de056402fd90dbb1dc47756ef7cbcc9d230a5eb8.tar.gz |
config.c: Tolerate UTF8 BOM at the beginning of config file
Unfortunately, the abomination of Windows Notepad likes to scatted
non-sensical UTF8 BOM marks across text files it edits. This is
especially troublesome when editing the Git configuration file,
and it does not appear to be particularly harmful to teach Git
to deal with this poo in the configfile.
Signed-off-by: Petr Baudis <petr.baudis@novartis.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -205,8 +205,27 @@ static int git_parse_file(config_fn_t fn, void *data) int baselen = 0; static char var[MAXNAME]; + /* U+FEFF Byte Order Mark in UTF8 */ + static const unsigned char *utf8_bom = (unsigned char *) "\xef\xbb\xbf"; + const unsigned char *bomptr = utf8_bom; + for (;;) { int c = get_next_char(); + if (bomptr && *bomptr) { + /* We are at the file beginning; skip UTF8-encoded BOM + * if present. Sane editors won't put this in on their + * own, but e.g. Windows Notepad will do it happily. */ + if ((unsigned char) c == *bomptr) { + bomptr++; + continue; + } else { + /* Do not tolerate partial BOM. */ + if (bomptr != utf8_bom) + break; + /* No BOM at file beginning. Cool. */ + bomptr = NULL; + } + } if (c == '\n') { if (config_file_eof) return 0; |