Skip to content

Commit 2d84f13

Browse files
stefanbellergitster
authored andcommitted
config: fix case sensitive subsection names on writing
A user reported a submodule issue regarding a section mix-up, but it could be boiled down to the following test case: $ git init test && cd test $ git config foo."Bar".key test $ git config foo."bar".key test $ tail -n 3 .git/config [foo "Bar"] key = test key = test Sub sections are case sensitive and we have a test for correctly reading them. However we do not have a test for writing out config correctly with case sensitive subsection names, which is why this went unnoticed in 6ae996f (git_config_set: make use of the config parser's event stream, 2018-04-09) Unfortunately we have to make a distinction between old style configuration that looks like [foo.Bar] key = test and the new quoted style as seen above. The old style is documented as case-agnostic, hence we need to keep 'strncasecmp'; although the resulting setting for the old style config differs from the configuration. That will be fixed in a follow up patch. Reported-by: JP Sugarbroad <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 999d902 commit 2d84f13

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

config.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct config_source {
3535
int eof;
3636
struct strbuf value;
3737
struct strbuf var;
38+
unsigned subsection_case_sensitive : 1;
3839

3940
int (*do_fgetc)(struct config_source *c);
4041
int (*do_ungetc)(int c, struct config_source *conf);
@@ -603,6 +604,7 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
603604

604605
static int get_extended_base_var(struct strbuf *name, int c)
605606
{
607+
cf->subsection_case_sensitive = 0;
606608
do {
607609
if (c == '\n')
608610
goto error_incomplete_line;
@@ -639,6 +641,7 @@ static int get_extended_base_var(struct strbuf *name, int c)
639641

640642
static int get_base_var(struct strbuf *name)
641643
{
644+
cf->subsection_case_sensitive = 1;
642645
for (;;) {
643646
int c = get_next_char();
644647
if (cf->eof)
@@ -2328,14 +2331,21 @@ static int store_aux_event(enum config_event_t type,
23282331
store->parsed[store->parsed_nr].type = type;
23292332

23302333
if (type == CONFIG_EVENT_SECTION) {
2334+
int (*cmpfn)(const char *, const char *, size_t);
2335+
23312336
if (cf->var.len < 2 || cf->var.buf[cf->var.len - 1] != '.')
23322337
return error("invalid section name '%s'", cf->var.buf);
23332338

2339+
if (cf->subsection_case_sensitive)
2340+
cmpfn = strncasecmp;
2341+
else
2342+
cmpfn = strncmp;
2343+
23342344
/* Is this the section we were looking for? */
23352345
store->is_keys_section =
23362346
store->parsed[store->parsed_nr].is_keys_section =
23372347
cf->var.len - 1 == store->baselen &&
2338-
!strncasecmp(cf->var.buf, store->key, store->baselen);
2348+
!cmpfn(cf->var.buf, store->key, store->baselen);
23392349
if (store->is_keys_section) {
23402350
store->section_seen = 1;
23412351
ALLOC_GROW(store->seen, store->seen_nr + 1,

t/t1300-config.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ test_expect_success 'setting different case sensitive subsections ' '
12601260
Qc = v2
12611261
[d "e"]
12621262
f = v1
1263+
[d "E"]
12631264
Qf = v2
12641265
EOF
12651266
# exact match

0 commit comments

Comments
 (0)