Skip to content

Commit 36cf1db

Browse files
committed
Support empty values for git_config_get_mapped and git_config_lookup_map_value
Signed-off-by: Sven Strickroth <email@cs-ware.de>
1 parent 86d0491 commit 36cf1db

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/config.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,9 +1227,6 @@ int git_config_lookup_map_value(
12271227
{
12281228
size_t i;
12291229

1230-
if (!value)
1231-
goto fail_parse;
1232-
12331230
for (i = 0; i < map_n; ++i) {
12341231
const git_configmap *m = maps + i;
12351232

@@ -1252,15 +1249,14 @@ int git_config_lookup_map_value(
12521249
break;
12531250

12541251
case GIT_CONFIGMAP_STRING:
1255-
if (strcasecmp(value, m->str_match) == 0) {
1252+
if (value && strcasecmp(value, m->str_match) == 0) {
12561253
*out = m->map_value;
12571254
return 0;
12581255
}
12591256
break;
12601257
}
12611258
}
12621259

1263-
fail_parse:
12641260
git_error_set(GIT_ERROR_CONFIG, "failed to map '%s'", value);
12651261
return -1;
12661262
}

tests/config/read.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,11 +955,13 @@ void test_config_read__get_mapped(void)
955955
cl_git_mkfile("./testconfig", "[header]\n key1 = 1\n key2 = true\n key3\n key4 = always\n key5 = false\n key6 = 0\n key7 = never\n");
956956
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
957957

958-
// check aprsing bool and string
958+
// check parsing bool and string
959959
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key1", _test_map1, ARRAY_SIZE(_test_map1)));
960960
cl_assert_equal_i(val, MAP_TRUE);
961961
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key2", _test_map1, ARRAY_SIZE(_test_map1)));
962962
cl_assert_equal_i(val, MAP_TRUE);
963+
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key3", _test_map1, ARRAY_SIZE(_test_map1)));
964+
cl_assert_equal_i(val, MAP_TRUE);
963965

964966
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key4", _test_map1, ARRAY_SIZE(_test_map1)));
965967
cl_assert_equal_i(val, MAP_ALWAYS);

0 commit comments

Comments
 (0)