diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-03-09 20:38:32 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-03-09 20:43:17 +0100 |
| commit | 54fef6ebcba8777caf389cba06556aab6f22b1cc (patch) | |
| tree | 9924808b98aa668158b5085a1995994285cf5405 /src/config_file.c | |
| parent | 6cfe3b3f12a059a044f94c63e495ab729cd9ec7b (diff) | |
| download | libgit2-54fef6ebcba8777caf389cba06556aab6f22b1cc.tar.gz | |
config: write out section headers with subsections correctly
write_section() mistakenly treated is input as the whole variable name
instead of simply the section (and possibly subsection) and would
confuse "section.subsection" as a section plus variable name and
produce a wrong section header.
Fix this and include a test for writing "section.subsection.var" and
reading it from the file.
Diffstat (limited to 'src/config_file.c')
| -rw-r--r-- | src/config_file.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/config_file.c b/src/config_file.c index 3c7c593ec..e1f4ef932 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -925,22 +925,18 @@ static int config_parse(diskfile_backend *cfg_file) static int write_section(git_filebuf *file, const char *key) { int error; - const char *fdot, *ldot; + const char *dot; git_buf buf = GIT_BUF_INIT; /* All of this just for [section "subsection"] */ - fdot = strchr(key, '.'); + dot = strchr(key, '.'); git_buf_putc(&buf, '['); - if (fdot == NULL) + if (dot == NULL) { git_buf_puts(&buf, key); - else - git_buf_put(&buf, key, fdot - key); - ldot = strrchr(key, '.'); - if (fdot != ldot && fdot != NULL) { - git_buf_putc(&buf, '"'); + } else { + git_buf_put(&buf, key, dot - key); /* TODO: escape */ - git_buf_put(&buf, fdot + 1, ldot - fdot - 1); - git_buf_putc(&buf, '"'); + git_buf_printf(&buf, " \"%s\"", dot + 1); } git_buf_puts(&buf, "]\n"); if (git_buf_oom(&buf)) |
