From: Junio C Hamano Date: Tue, 5 May 2020 21:54:29 +0000 (-0700) Subject: Merge branch 'js/partial-urlmatch-2.17' X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=da05cacd8a4e7c3d6d8c84aa2c1d45684717ac95;p=git.git Merge branch 'js/partial-urlmatch-2.17' Recent updates broke parsing of "credential.." where is not a full URL (e.g. [credential "https://"] helper = ...) stopped working, which has been corrected. * js/partial-urlmatch-2.17: credential: handle `credential..` again credential: optionally allow partial URLs in credential_from_url_gently() credential: fix grammar --- da05cacd8a4e7c3d6d8c84aa2c1d45684717ac95 diff --cc credential.c index d72e2ed0d8,c1a9ca4e48..c19322d98f --- a/credential.c +++ b/credential.c @@@ -396,17 -395,10 +423,17 @@@ static int credential_from_url_1(struc 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, ':'); - slash = strchrnul(cp, '/'); + + /* + * A query or fragment marker before the slash ends the host portion. + * We'll just continue to call this "slash" for simplicity. Notably our + * "trim leading slashes" part won't skip over this part of the path, + * but that's what we'd want. + */ + slash = cp + strcspn(cp, "/?#"); if (!at || slash <= at) { /* Case (1) */ diff --cc t/t0300-credentials.sh index 91a007fbfa,da4b315d6d..bc2d74098f --- a/t/t0300-credentials.sh +++ b/t/t0300-credentials.sh @@@ -620,38 -448,42 +620,76 @@@ test_expect_success 'credential system test_i18ncmp expect stderr ' +# usage: check_host_and_path +check_host_and_path () { + # we always parse the path component, but we need this to make sure it + # is passed to the helper + test_config credential.useHTTPPath true && + check fill "verbatim user pass" <<-EOF + url=$1 + -- + protocol=https + host=$2 + path=$3 + username=user + password=pass + -- + verbatim: get + verbatim: protocol=https + verbatim: host=$2 + verbatim: path=$3 + EOF +} + +test_expect_success 'url parser handles bare query marker' ' + check_host_and_path https://example.com?foo.git example.com ?foo.git +' + +test_expect_success 'url parser handles bare fragment marker' ' + check_host_and_path https://example.com#foo.git example.com "#foo.git" +' + +test_expect_success 'url parser not confused by encoded markers' ' + check_host_and_path https://example.com%23%3f%2f/foo.git \ + "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 stdout && + grep yep stdout || + return 1 + done && + + for partial in \ + dont.use.this \ + http:// \ + /repo + do + git -c credential.$partial.helper=yep \ + credential fill stdout && + ! grep yep stdout || + return 1 + done && + + git -c credential.$partial.helper=yep \ + -c credential.with%0anewline.username=uh-oh \ + credential fill stdout 2>stderr && + test_i18ngrep "skipping credential lookup for key" stderr + ' + test_done