diff options
author | Russell Belfer <rb@github.com> | 2012-08-12 07:59:30 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-08-12 07:59:30 -0700 |
commit | a1ecddf01c5546b3f29cd546f4a469263cc6785e (patch) | |
tree | 256c14d824feba4e83a52cfdf2a5b1defe1c2b2b | |
parent | c9d78bde943213f4c2594d1df175336573678b74 (diff) | |
download | libgit2-a1ecddf01c5546b3f29cd546f4a469263cc6785e.tar.gz |
Fix config parser boundary logic
The config file parser was not working right if there was no
whitespace between the value name and the equals sign. This
fixes that.
-rw-r--r-- | src/config_file.c | 7 | ||||
-rw-r--r-- | tests-clar/config/read.c | 16 | ||||
-rw-r--r-- | tests-clar/resources/config/config14 | 4 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/config_file.c b/src/config_file.c index 80c63d2a3..433423582 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -1343,10 +1343,9 @@ static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_val else value_start = var_end + 1; - if (git__isspace(var_end[-1])) { - do var_end--; - while (git__isspace(var_end[0])); - } + var_end--; + while (git__isspace(*var_end)) + var_end--; *var_name = git__strndup(line, var_end - line + 1); GITERR_CHECK_ALLOC(*var_name); diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c index 574ff8196..fcd22463d 100644 --- a/tests-clar/config/read.c +++ b/tests-clar/config/read.c @@ -266,6 +266,22 @@ void test_config_read__foreach_match(void) git_config_free(cfg); } +void test_config_read__whitespace_not_required_around_assignment(void) +{ + git_config *cfg; + const char *str; + + cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14"))); + + cl_git_pass(git_config_get_string(&str, cfg, "a.b")); + cl_assert_equal_s(str, "c"); + + cl_git_pass(git_config_get_string(&str, cfg, "d.e")); + cl_assert_equal_s(str, "f"); + + git_config_free(cfg); +} + #if 0 BEGIN_TEST(config10, "a repo's config overrides the global config") diff --git a/tests-clar/resources/config/config14 b/tests-clar/resources/config/config14 new file mode 100644 index 000000000..ef2198c45 --- /dev/null +++ b/tests-clar/resources/config/config14 @@ -0,0 +1,4 @@ +[a] + b=c +[d] + e = f |