зеркало из https://github.com/microsoft/git.git
Merge branch 'js/partial-urlmatch-2.17'
Recent updates broke parsing of "credential.<url>.<key>" where <url> is not a full URL (e.g. [credential "https://"] helper = ...) stopped working, which has been corrected. * js/partial-urlmatch-2.17: credential: handle `credential.<partial-URL>.<key>` again credential: optionally allow partial URLs in credential_from_url_gently() credential: fix grammar
This commit is contained in:
Коммит
da05cacd8a
48
credential.c
48
credential.c
|
@ -37,6 +37,10 @@ int credential_match(const struct credential *want,
|
|||
#undef CHECK
|
||||
}
|
||||
|
||||
|
||||
static int credential_from_potentially_partial_url(struct credential *c,
|
||||
const char *url);
|
||||
|
||||
static int credential_config_callback(const char *var, const char *value,
|
||||
void *data)
|
||||
{
|
||||
|
@ -377,8 +381,31 @@ static int check_url_component(const char *url, int quiet,
|
|||
return -1;
|
||||
}
|
||||
|
||||
int credential_from_url_gently(struct credential *c, const char *url,
|
||||
int quiet)
|
||||
/*
|
||||
* Potentially-partial URLs can, but do not have to, contain
|
||||
*
|
||||
* - a protocol (or scheme) of the form "<protocol>://"
|
||||
*
|
||||
* - a host name (the part after the protocol and before the first slash after
|
||||
* that, if any)
|
||||
*
|
||||
* - a user name and potentially a password (as "<user>[:<password>]@" part of
|
||||
* the host name)
|
||||
*
|
||||
* - a path (the part after the host name, if any, starting with the slash)
|
||||
*
|
||||
* Missing parts will be left unset in `struct credential`. Thus, `https://`
|
||||
* will have only the `protocol` set, `example.com` only the host name, and
|
||||
* `/git` only the path.
|
||||
*
|
||||
* Note that an empty host name in an otherwise fully-qualified URL (e.g.
|
||||
* `cert:///path/to/cert.pem`) will be treated as unset if we expect the URL to
|
||||
* be potentially partial, and only then (otherwise, the empty string is used).
|
||||
*
|
||||
* The credential_from_url() function does not allow partial URLs.
|
||||
*/
|
||||
static int credential_from_url_1(struct credential *c, const char *url,
|
||||
int allow_partial_url, int quiet)
|
||||
{
|
||||
const char *at, *colon, *cp, *slash, *host, *proto_end;
|
||||
|
||||
|
@ -391,12 +418,12 @@ int credential_from_url_gently(struct credential *c, const char *url,
|
|||
* (3) proto://<user>:<pass>@<host>/...
|
||||
*/
|
||||
proto_end = strstr(url, "://");
|
||||
if (!proto_end || proto_end == url) {
|
||||
if (!allow_partial_url && (!proto_end || proto_end == url)) {
|
||||
if (!quiet)
|
||||
warning(_("url has no scheme: %s"), url);
|
||||
return -1;
|
||||
}
|
||||
cp = proto_end + 3;
|
||||
cp = proto_end ? proto_end + 3 : url;
|
||||
at = strchr(cp, '@');
|
||||
colon = strchr(cp, ':');
|
||||
|
||||
|
@ -427,7 +454,9 @@ int credential_from_url_gently(struct credential *c, const char *url,
|
|||
host = at + 1;
|
||||
}
|
||||
|
||||
if (proto_end && proto_end - url > 0)
|
||||
c->protocol = xmemdupz(url, proto_end - url);
|
||||
if (!allow_partial_url || slash - host > 0)
|
||||
c->host = url_decode_mem(host, slash - host);
|
||||
/* Trim leading and trailing slashes from path */
|
||||
while (*slash == '/')
|
||||
|
@ -450,6 +479,17 @@ int credential_from_url_gently(struct credential *c, const char *url,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int credential_from_potentially_partial_url(struct credential *c,
|
||||
const char *url)
|
||||
{
|
||||
return credential_from_url_1(c, url, 1, 0);
|
||||
}
|
||||
|
||||
int credential_from_url_gently(struct credential *c, const char *url, int quiet)
|
||||
{
|
||||
return credential_from_url_1(c, url, 0, quiet);
|
||||
}
|
||||
|
||||
void credential_from_url(struct credential *c, const char *url)
|
||||
{
|
||||
if (credential_from_url_gently(c, url, 0) < 0)
|
||||
|
|
|
@ -654,4 +654,42 @@ test_expect_success 'url parser not confused by encoded markers' '
|
|||
"example.com#?/" foo.git
|
||||
'
|
||||
|
||||
test_expect_success 'credential config with partial URLs' '
|
||||
echo "echo password=yep" | write_script git-credential-yep &&
|
||||
test_write_lines url=https://user@example.com/repo.git >stdin &&
|
||||
for partial in \
|
||||
example.com \
|
||||
user@example.com \
|
||||
https:// \
|
||||
https://example.com \
|
||||
https://example.com/ \
|
||||
https://user@example.com \
|
||||
https://user@example.com/ \
|
||||
https://example.com/repo.git \
|
||||
https://user@example.com/repo.git \
|
||||
/repo.git
|
||||
do
|
||||
git -c credential.$partial.helper=yep \
|
||||
credential fill <stdin >stdout &&
|
||||
grep yep stdout ||
|
||||
return 1
|
||||
done &&
|
||||
|
||||
for partial in \
|
||||
dont.use.this \
|
||||
http:// \
|
||||
/repo
|
||||
do
|
||||
git -c credential.$partial.helper=yep \
|
||||
credential fill <stdin >stdout &&
|
||||
! grep yep stdout ||
|
||||
return 1
|
||||
done &&
|
||||
|
||||
git -c credential.$partial.helper=yep \
|
||||
-c credential.with%0anewline.username=uh-oh \
|
||||
credential fill <stdin >stdout 2>stderr &&
|
||||
test_i18ngrep "skipping credential lookup for key" stderr
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Загрузка…
Ссылка в новой задаче