From: Jeff King Date: Sun, 23 May 2010 09:19:44 +0000 (-0400) Subject: decode file:// and ssh:// URLs X-Git-Tag: v1.7.2-rc0~8^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9d2e942070b235e1f4a0b8dd4c55a6b3f0fe914a;p=git.git decode file:// and ssh:// URLs We generally treat these as equivalent to "/path/to/repo" and "host:path_to_repo" respectively. However, they are URLs and as such may be percent-encoded. The current code simply uses them as-is without any decoding. With this patch, we will now percent-decode any file:// or ssh:// url (or ssh+git, git+ssh, etc) at the transport layer. We continue to treat plain paths and "host:path" syntax literally. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/connect.c b/connect.c index 9ae991ac4..0119bd377 100644 --- a/connect.c +++ b/connect.c @@ -5,6 +5,7 @@ #include "refs.h" #include "run-command.h" #include "remote.h" +#include "url.h" static char *server_capabilities; @@ -450,7 +451,7 @@ static struct child_process no_fork; struct child_process *git_connect(int fd[2], const char *url_orig, const char *prog, int flags) { - char *url = xstrdup(url_orig); + char *url; char *host, *path; char *end; int c; @@ -466,6 +467,11 @@ struct child_process *git_connect(int fd[2], const char *url_orig, */ signal(SIGCHLD, SIG_DFL); + if (is_url(url_orig)) + url = url_decode(url_orig); + else + url = xstrdup(url_orig); + host = strstr(url, "://"); if (host) { *host = '\0'; diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 678cee502..8abb71afc 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -176,4 +176,16 @@ test_expect_success 'clone respects global branch.autosetuprebase' ' ) ' +test_expect_success 'respect url-encoding of file://' ' + git init x+y && + test_must_fail git clone "file://$PWD/x+y" xy-url && + git clone "file://$PWD/x%2By" xy-url +' + +test_expect_success 'do not respect url-encoding of non-url path' ' + git init x+y && + test_must_fail git clone x%2By xy-regular && + git clone x+y xy-regular +' + test_done