Skip to content

Commit 9d2e942

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 638794c commit 9d2e942

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

connect.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "refs.h"
66
#include "run-command.h"
77
#include "remote.h"
8+
#include "url.h"
89

910
static char *server_capabilities;
1011

@@ -450,7 +451,7 @@ static struct child_process no_fork;
450451
struct child_process *git_connect(int fd[2], const char *url_orig,
451452
const char *prog, int flags)
452453
{
453-
char *url = xstrdup(url_orig);
454+
char *url;
454455
char *host, *path;
455456
char *end;
456457
int c;
@@ -466,6 +467,11 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
466467
*/
467468
signal(SIGCHLD, SIG_DFL);
468469

470+
if (is_url(url_orig))
471+
url = url_decode(url_orig);
472+
else
473+
url = xstrdup(url_orig);
474+
469475
host = strstr(url, "://");
470476
if (host) {
471477
*host = '\0';

t/t5601-clone.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,16 @@ test_expect_success 'clone respects global branch.autosetuprebase' '
176176
)
177177
'
178178

179+
test_expect_success 'respect url-encoding of file://' '
180+
git init x+y &&
181+
test_must_fail git clone "file://$PWD/x+y" xy-url &&
182+
git clone "file://$PWD/x%2By" xy-url
183+
'
184+
185+
test_expect_success 'do not respect url-encoding of non-url path' '
186+
git init x+y &&
187+
test_must_fail git clone x%2By xy-regular &&
188+
git clone x+y xy-regular
189+
'
190+
179191
test_done

0 commit comments

Comments
 (0)