config: really keep value-internal whitespace verbatim
Fix a bug in function parse_value() that prevented whitespace characters (i.e. spaces and horizontal tabs) found inside configuration option values from being parsed and returned in their original form. The bug caused any number of consecutive whitespace characters to be wrongly "squashed" into the same number of space characters. This bug was introduced back in July 2009, in commitebdaae372b
("config: Keep inner whitespace verbatim"). Further investigation showed that setting a configuration value, by invoking git-config(1), converts value-internal horizontal tabs into "\t" escape sequences, which the buggy value-parsing logic in function parse_value() didn't "squash" into spaces. That's why the test included in theebdaae37
commit passed, which presumably made the bug remain undetected for this long. On the other hand, value-internal literal horizontal tab characters, found in a configuration file edited by hand, do get "squashed" by the value-parsing logic, so the right choice was to fix this bug by making the value-internal whitespace characters preserved verbatim. Signed-off-by: Dragan Simic <dsimic@manjaro.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
0d49b1e5a8
commit
f0b8944430
13
config.c
13
config.c
@ -819,7 +819,8 @@ static int get_next_char(struct config_source *cs)
|
||||
|
||||
static char *parse_value(struct config_source *cs)
|
||||
{
|
||||
int quote = 0, comment = 0, space = 0;
|
||||
int quote = 0, comment = 0;
|
||||
size_t trim_len = 0;
|
||||
|
||||
strbuf_reset(&cs->value);
|
||||
for (;;) {
|
||||
@ -829,13 +830,17 @@ static char *parse_value(struct config_source *cs)
|
||||
cs->linenr--;
|
||||
return NULL;
|
||||
}
|
||||
if (trim_len)
|
||||
strbuf_setlen(&cs->value, trim_len);
|
||||
return cs->value.buf;
|
||||
}
|
||||
if (comment)
|
||||
continue;
|
||||
if (isspace(c) && !quote) {
|
||||
if (!trim_len)
|
||||
trim_len = cs->value.len;
|
||||
if (cs->value.len)
|
||||
space++;
|
||||
strbuf_addch(&cs->value, c);
|
||||
continue;
|
||||
}
|
||||
if (!quote) {
|
||||
@ -844,8 +849,8 @@ static char *parse_value(struct config_source *cs)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (; space; space--)
|
||||
strbuf_addch(&cs->value, ' ');
|
||||
if (trim_len)
|
||||
trim_len = 0;
|
||||
if (c == '\\') {
|
||||
c = get_next_char(cs);
|
||||
switch (c) {
|
||||
|
Reference in New Issue
Block a user