Fix username and password extraction from HTTP URLs
Change the authentification initialisation to percent-decode username and password for HTTP URLs. Signed-off-by: Gabriel Corona <gabriel.corona@enst-bretagne.fr> Acked-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Gabriel Corona committed
Nov 14, 2010 at 02:51 UTC
f39f72d8cf03b61407f64460eba3357ec532280e
2 files changed
+12
-2
http.c
+11
-1
@@ -2,6 +2,7 @@
2
#include "pack.h"
3
#include "sideband.h"
4
#include "run-command.h"
5
+#include "url.h"
6
7
int data_received;
8
int active_requests;
@@ -297,7 +298,7 @@ static CURL *get_curl_handle(void)
298
299
static void http_auth_init(const char *url)
300
{
300
- char *at, *colon, *cp, *slash;
301
+ char *at, *colon, *cp, *slash, *decoded;
302
int len;
303
304
cp = strstr(url, "://");
@@ -322,16 +323,25 @@ static void http_auth_init(const char *url)
323
user_name = xmalloc(len + 1);
324
memcpy(user_name, cp, len);
325
user_name[len] = '\0';
326
+ decoded = url_decode(user_name);
327
+ free(user_name);
328
+ user_name = decoded;
329
user_pass = NULL;
330
} else {
331
len = colon - cp;
332
user_name = xmalloc(len + 1);
333
memcpy(user_name, cp, len);
334
user_name[len] = '\0';
335
+ decoded = url_decode(user_name);
336
+ free(user_name);
337
+ user_name = decoded;
338
len = at - (colon + 1);
339
user_pass = xmalloc(len + 1);
340
memcpy(user_pass, colon + 1, len);
341
user_pass[len] = '\0';
342
+ decoded = url_decode(user_pass);
343
+ free(user_pass);
344
+ user_pass = decoded;
345
}
346
}
347
t/t5550-http-fetch.sh
+1
-1
@@ -34,7 +34,7 @@ test_expect_success 'clone http repository' '
34
test_cmp file clone/file
35
'
36
37
-test_expect_failure 'clone http repository with authentication' '
37
+test_expect_success 'clone http repository with authentication' '
38
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
39
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git" &&
40
git clone $AUTH_HTTPD_URL/auth/repo.git clone-auth &&