mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-02 14:37:30 +00:00
config: escape subsection names when creating them
This allows us to set options like "some.foo\\ish.var". This closes #830
This commit is contained in:
parent
c8a1892e71
commit
5d9cfa07ac
@ -983,9 +983,12 @@ static int write_section(git_filebuf *file, const char *key)
|
||||
if (dot == NULL) {
|
||||
git_buf_puts(&buf, key);
|
||||
} else {
|
||||
char *escaped;
|
||||
git_buf_put(&buf, key, dot - key);
|
||||
/* TODO: escape */
|
||||
git_buf_printf(&buf, " \"%s\"", dot + 1);
|
||||
escaped = escape_value(dot + 1);
|
||||
GITERR_CHECK_ALLOC(escaped);
|
||||
git_buf_printf(&buf, " \"%s\"", escaped);
|
||||
git__free(escaped);
|
||||
}
|
||||
git_buf_puts(&buf, "]\n");
|
||||
|
||||
|
@ -59,3 +59,25 @@ void test_config_stress__comments(void)
|
||||
|
||||
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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user