Commit 5d9cfa07 by Carlos Martín Nieto

config: escape subsection names when creating them

This allows us to set options like "some.foo\\ish.var".

This closes #830
parent c8a1892e
...@@ -983,9 +983,12 @@ static int write_section(git_filebuf *file, const char *key) ...@@ -983,9 +983,12 @@ static int write_section(git_filebuf *file, const char *key)
if (dot == NULL) { if (dot == NULL) {
git_buf_puts(&buf, key); git_buf_puts(&buf, key);
} else { } else {
char *escaped;
git_buf_put(&buf, key, dot - key); git_buf_put(&buf, key, dot - key);
/* TODO: escape */ escaped = escape_value(dot + 1);
git_buf_printf(&buf, " \"%s\"", dot + 1); GITERR_CHECK_ALLOC(escaped);
git_buf_printf(&buf, " \"%s\"", escaped);
git__free(escaped);
} }
git_buf_puts(&buf, "]\n"); git_buf_puts(&buf, "]\n");
......
...@@ -59,3 +59,25 @@ void test_config_stress__comments(void) ...@@ -59,3 +59,25 @@ void test_config_stress__comments(void)
git_config_free(config); git_config_free(config);
} }
void test_config_stress__escape_subsection_names(void)
{
struct git_config_file *file;
git_config *config;
const char *str;
cl_assert(git_path_exists("git-test-config"));
cl_git_pass(git_config_file__ondisk(&file, "git-test-config"));
cl_git_pass(git_config_new(&config));
cl_git_pass(git_config_add_file(config, file, 0));
cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo"));
git_config_free(config);
cl_git_pass(git_config_file__ondisk(&file, "git-test-config"));
cl_git_pass(git_config_new(&config));
cl_git_pass(git_config_add_file(config, file, 0));
cl_git_pass(git_config_get_string(&str, config, "some.sec\\tion.other"));
cl_assert(!strcmp("foo", str));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment