mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-06 08:24:01 +00:00
config: distinguish between a lone variable name and one without rhs
'[section] variable' and '[section] variable =' behave differently when parsed as booleans, so we need to store that distinction internally.
This commit is contained in:
parent
3ee078c0f7
commit
47db054df0
@ -1432,8 +1432,10 @@ static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_val
|
|||||||
else if (value_start[0] != '\0') {
|
else if (value_start[0] != '\0') {
|
||||||
*var_value = fixup_line(value_start, 0);
|
*var_value = fixup_line(value_start, 0);
|
||||||
GITERR_CHECK_ALLOC(*var_value);
|
GITERR_CHECK_ALLOC(*var_value);
|
||||||
|
} else { /* equals sign but missing rhs */
|
||||||
|
*var_value = git__strdup("");
|
||||||
|
GITERR_CHECK_ALLOC(*var_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
git__free(line);
|
git__free(line);
|
||||||
|
@ -136,7 +136,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
|
|||||||
if ((error = git_config_get_string(&val, config, git_buf_cstr(&buf))) < 0)
|
if ((error = git_config_get_string(&val, config, git_buf_cstr(&buf))) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!val) {
|
if (!val || strlen(val) == 0) {
|
||||||
giterr_set(GITERR_INVALID, "Malformed remote '%s' - missing URL", name);
|
giterr_set(GITERR_INVALID, "Malformed remote '%s' - missing URL", name);
|
||||||
error = -1;
|
error = -1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
11
src/util.c
11
src/util.c
@ -432,12 +432,8 @@ int git__strcmp_cb(const void *a, const void *b)
|
|||||||
int git__parse_bool(int *out, const char *value)
|
int git__parse_bool(int *out, const char *value)
|
||||||
{
|
{
|
||||||
/* A missing value means true */
|
/* A missing value means true */
|
||||||
if (value == NULL) {
|
if (value == NULL ||
|
||||||
*out = 1;
|
!strcasecmp(value, "true") ||
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcasecmp(value, "true") ||
|
|
||||||
!strcasecmp(value, "yes") ||
|
!strcasecmp(value, "yes") ||
|
||||||
!strcasecmp(value, "on")) {
|
!strcasecmp(value, "on")) {
|
||||||
*out = 1;
|
*out = 1;
|
||||||
@ -445,7 +441,8 @@ int git__parse_bool(int *out, const char *value)
|
|||||||
}
|
}
|
||||||
if (!strcasecmp(value, "false") ||
|
if (!strcasecmp(value, "false") ||
|
||||||
!strcasecmp(value, "no") ||
|
!strcasecmp(value, "no") ||
|
||||||
!strcasecmp(value, "off")) {
|
!strcasecmp(value, "off") ||
|
||||||
|
value[0] == '\0') {
|
||||||
*out = 0;
|
*out = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,12 @@ void test_config_read__lone_variable(void)
|
|||||||
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
|
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
|
||||||
cl_assert(i == 1);
|
cl_assert(i == 1);
|
||||||
|
|
||||||
|
cl_git_pass(git_config_get_string(&str, cfg, "some.section.variableeq"));
|
||||||
|
cl_assert_equal_s(str, "");
|
||||||
|
|
||||||
|
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq"));
|
||||||
|
cl_assert(i == 0);
|
||||||
|
|
||||||
git_config_free(cfg);
|
git_config_free(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
# A variable name on its own is valid
|
# A variable name on its own is valid
|
||||||
[some.section]
|
[some.section]
|
||||||
variable
|
variable
|
||||||
|
# A variable and '=' is accepted, but it's not considered true
|
||||||
|
variableeq =
|
||||||
|
Loading…
Reference in New Issue
Block a user