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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
May 23, 2010 at 05:19 UTC
9d2e942070b235e1f4a0b8dd4c55a6b3f0fe914a
2 files changed
+19
-1
connect.c
+7
-1
@@ -5,6 +5,7 @@
5
#include "refs.h"
6
#include "run-command.h"
7
#include "remote.h"
8
+#include "url.h"
9
10
static char *server_capabilities;
11
@@ -450,7 +451,7 @@ static struct child_process no_fork;
451
struct child_process *git_connect(int fd[2], const char *url_orig,
452
const char *prog, int flags)
453
{
453
- char *url = xstrdup(url_orig);
454
+ char *url;
455
char *host, *path;
456
char *end;
457
int c;
@@ -466,6 +467,11 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
467
*/
468
signal(SIGCHLD, SIG_DFL);
469
470
+ if (is_url(url_orig))
471
+ url = url_decode(url_orig);
472
+ else
473
+ url = xstrdup(url_orig);
474
+
475
host = strstr(url, "://");
476
if (host) {
477
*host = '\0';
t/t5601-clone.sh
+12
@@ -176,4 +176,16 @@ test_expect_success 'clone respects global branch.autosetuprebase' '
176
)
177
'
178
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
+
191
test_done