Sanity-check config variable names
Sanity-check config variable names when adding and retrieving them. As a side effect code duplication between git_config_set_multivar and get_value (in builtin/config.c) was removed and the common functionality was placed in git_config_parse_key. This breaks a test in t1300 which used invalid section-less keys in the tests for "git -c". However, allowing such names there was useless, since there was no way to set them via config file, and no part of git actually tried to use section-less keys. This patch updates the test to use more realistic examples as well as adding its own test. Signed-off-by: Libor Pechacek <lpechacek@suse.cz> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
597a630542
commit
b09c53a3e3
@ -153,7 +153,6 @@ static int show_config(const char *key_, const char *value_, void *cb)
|
||||
static int get_value(const char *key_, const char *regex_)
|
||||
{
|
||||
int ret = -1;
|
||||
char *tl;
|
||||
char *global = NULL, *repo_config = NULL;
|
||||
const char *system_wide = NULL, *local;
|
||||
|
||||
@ -167,18 +166,32 @@ static int get_value(const char *key_, const char *regex_)
|
||||
system_wide = git_etc_gitconfig();
|
||||
}
|
||||
|
||||
key = xstrdup(key_);
|
||||
for (tl=key+strlen(key)-1; tl >= key && *tl != '.'; --tl)
|
||||
*tl = tolower(*tl);
|
||||
for (tl=key; *tl && *tl != '.'; ++tl)
|
||||
*tl = tolower(*tl);
|
||||
|
||||
if (use_key_regexp) {
|
||||
char *tl;
|
||||
|
||||
/*
|
||||
* NEEDSWORK: this naive pattern lowercasing obviously does not
|
||||
* work for more complex patterns like "^[^.]*Foo.*bar".
|
||||
* Perhaps we should deprecate this altogether someday.
|
||||
*/
|
||||
|
||||
key = xstrdup(key_);
|
||||
for (tl = key + strlen(key) - 1;
|
||||
tl >= key && *tl != '.';
|
||||
tl--)
|
||||
*tl = tolower(*tl);
|
||||
for (tl = key; *tl && *tl != '.'; tl++)
|
||||
*tl = tolower(*tl);
|
||||
|
||||
key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
|
||||
if (regcomp(key_regexp, key, REG_EXTENDED)) {
|
||||
fprintf(stderr, "Invalid key pattern: %s\n", key_);
|
||||
free(key);
|
||||
goto free_strings;
|
||||
}
|
||||
} else {
|
||||
if (git_config_parse_key(key_, &key, NULL))
|
||||
goto free_strings;
|
||||
}
|
||||
|
||||
if (regex_) {
|
||||
|
Reference in New Issue
Block a user