author | Junio C Hamano <gitster@pobox.com> | |
Mon, 26 Mar 2012 19:10:05 +0000 (12:10 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 26 Mar 2012 19:10:05 +0000 (12:10 -0700) |
* ms/maint-config-error-at-eol-linecount:
config: report errors at the EOL with correct line number
config: report errors at the EOL with correct line number
config.c | patch | blob | history | |
t/t1300-repo-config.sh | patch | blob | history |
diff --git a/config.c b/config.c
index 40f9c6d10317ed47f7786e5c328df3ab6f167e7c..818ba6df00e342f55fb7151b05299848240e61bd 100644 (file)
--- a/config.c
+++ b/config.c
for (;;) {
int c = get_next_char();
if (c == '\n') {
- if (quote)
+ if (quote) {
+ cf->linenr--;
return NULL;
+ }
return cf->value.buf;
}
if (comment)
{
do {
if (c == '\n')
- return -1;
+ goto error_incomplete_line;
c = get_next_char();
} while (isspace(c));
for (;;) {
int c = get_next_char();
if (c == '\n')
- return -1;
+ goto error_incomplete_line;
if (c == '"')
break;
if (c == '\\') {
c = get_next_char();
if (c == '\n')
- return -1;
+ goto error_incomplete_line;
}
name[baselen++] = c;
if (baselen > MAXNAME / 2)
if (get_next_char() != ']')
return -1;
return baselen;
+error_incomplete_line:
+ cf->linenr--;
+ return -1;
}
static int get_base_var(char *name)
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 0690e0edf4e758200d4febb1c7837b5c7059add6..728a965669e7a69014b950b8abbc672702caca27 100755 (executable)
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
test_must_fail git -c "" rev-parse
'
+# malformed configuration files
+test_expect_success 'barf on syntax error' '
+ cat >.git/config <<-\EOF &&
+ # broken section line
+ [section]
+ key garbage
+ EOF
+ test_must_fail git config --get section.key >actual 2>error &&
+ grep " line 3 " error
+'
+
+test_expect_success 'barf on incomplete section header' '
+ cat >.git/config <<-\EOF &&
+ # broken section line
+ [section
+ key = value
+ EOF
+ test_must_fail git config --get section.key >actual 2>error &&
+ grep " line 2 " error
+'
+
+test_expect_success 'barf on incomplete string' '
+ cat >.git/config <<-\EOF &&
+ # broken section line
+ [section]
+ key = "value string
+ EOF
+ test_must_fail git config --get section.key >actual 2>error &&
+ grep " line 3 " error
+'
+
test_done