diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-03-05 13:13:00 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-03-05 13:13:00 -0800 |
commit | 2250406bfdf8d9d890f53b651868363a304a7701 (patch) | |
tree | f3b6347563755f13f9d4af9f62d08dae8654c1f1 | |
parent | Merge branch 'jk/decimal-width-for-uintmax' into maint (diff) | |
parent | config_buf_ungetc: warn when pushing back a random character (diff) | |
download | tgif-2250406bfdf8d9d890f53b651868363a304a7701.tar.xz |
Merge branch 'jk/config-no-ungetc-eof' into maint
Reading configuration from a blob object, when it ends with a lone
CR, use to confuse the configuration parser.
* jk/config-no-ungetc-eof:
config_buf_ungetc: warn when pushing back a random character
config: do not ungetc EOF
-rw-r--r-- | config.c | 11 | ||||
-rwxr-xr-x | t/t1307-config-blob.sh | 9 |
2 files changed, 17 insertions, 3 deletions
@@ -73,8 +73,12 @@ static int config_buf_fgetc(struct config_source *conf) static int config_buf_ungetc(int c, struct config_source *conf) { - if (conf->u.buf.pos > 0) - return conf->u.buf.buf[--conf->u.buf.pos]; + if (conf->u.buf.pos > 0) { + conf->u.buf.pos--; + if (conf->u.buf.buf[conf->u.buf.pos] != c) + die("BUG: config_buf can only ungetc the same character"); + return c; + } return EOF; } @@ -235,7 +239,8 @@ static int get_next_char(void) /* DOS like systems */ c = cf->do_fgetc(cf); if (c != '\n') { - cf->do_ungetc(c, cf); + if (c != EOF) + cf->do_ungetc(c, cf); c = '\r'; } } diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh index fdc257e66f..3c6791e6be 100755 --- a/t/t1307-config-blob.sh +++ b/t/t1307-config-blob.sh @@ -67,4 +67,13 @@ test_expect_success 'parse errors in blobs are properly attributed' ' grep "HEAD:config" err ' +test_expect_success 'can parse blob ending with CR' ' + printf "[some]key = value\\r" >config && + git add config && + git commit -m CR && + echo value >expect && + git config --blob=HEAD:config some.key >actual && + test_cmp expect actual +' + test_done |