Skip to content

Commit

Permalink
Merge branch 'jk/config-no-ungetc-eof'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed Feb 18, 2015
2 parents 2c1f554 + 1d0655c commit de15bdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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';
}
}
Expand Down
9 changes: 9 additions & 0 deletions t/t1307-config-blob.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit de15bdb

Please sign in to comment.