Skip to content

Commit f0b8944

Browse files
Dragan Simicgitster
authored andcommitted
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 commit ebdaae3 ("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 the ebdaae3 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d49b1e commit f0b8944

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

config.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,8 @@ static int get_next_char(struct config_source *cs)
819819

820820
static char *parse_value(struct config_source *cs)
821821
{
822-
int quote = 0, comment = 0, space = 0;
822+
int quote = 0, comment = 0;
823+
size_t trim_len = 0;
823824

824825
strbuf_reset(&cs->value);
825826
for (;;) {
@@ -829,13 +830,17 @@ static char *parse_value(struct config_source *cs)
829830
cs->linenr--;
830831
return NULL;
831832
}
833+
if (trim_len)
834+
strbuf_setlen(&cs->value, trim_len);
832835
return cs->value.buf;
833836
}
834837
if (comment)
835838
continue;
836839
if (isspace(c) && !quote) {
840+
if (!trim_len)
841+
trim_len = cs->value.len;
837842
if (cs->value.len)
838-
space++;
843+
strbuf_addch(&cs->value, c);
839844
continue;
840845
}
841846
if (!quote) {
@@ -844,8 +849,8 @@ static char *parse_value(struct config_source *cs)
844849
continue;
845850
}
846851
}
847-
for (; space; space--)
848-
strbuf_addch(&cs->value, ' ');
852+
if (trim_len)
853+
trim_len = 0;
849854
if (c == '\\') {
850855
c = get_next_char(cs);
851856
switch (c) {

0 commit comments

Comments
 (0)