git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv2 2/2] Fix username and password extraction from HTTP URLs

From
GCGabriel Corona <gabriel.corona@enst-bretagne.fr>
Date
Nov 14, 2010, 01:51 UTC
Message-ID
<1289699475-11364-3-git-send-email-gabriel.corona@enst-bretagne.fr>
In-Reply-To
<1289699475-11364-1-git-send-email-gabriel.corona@enst-bretagne.fr>

Change the authentification initialisation to percent-decode username and password for HTTP URLs.

Signed-off-by: Gabriel Corona <gabriel.corona@enst-bretagne.fr>
---
 http.c                |   12 +++++++++++-
 t/t5550-http-fetch.sh |    2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/http.c b/http.c
index 0a5011f..c9393a8 100644
--- a/http.c
+++ b/http.c
@@ -2,6 +2,7 @@
 #include "pack.h"
 #include "sideband.h"
 #include "run-command.h"
+#include "url.h"
 
 int data_received;
 int active_requests;
@@ -297,7 +298,7 @@ static CURL *get_curl_handle(void)
 
 static void http_auth_init(const char *url)
 {
-	char *at, *colon, *cp, *slash;
+	char *at, *colon, *cp, *slash, *decoded;
 	int len;
 
 	cp = strstr(url, "://");
@@ -322,16 +323,25 @@ static void http_auth_init(const char *url)
 		user_name = xmalloc(len + 1);
 		memcpy(user_name, cp, len);
 		user_name[len] = '\0';
+		decoded = url_decode(user_name);
+		free(user_name);
+		user_name = decoded;
 		user_pass = NULL;
 	} else {
 		len = colon - cp;
 		user_name = xmalloc(len + 1);
 		memcpy(user_name, cp, len);
 		user_name[len] = '\0';
+		decoded = url_decode(user_name);
+		free(user_name);
+		user_name = decoded;
 		len = at - (colon + 1);
 		user_pass = xmalloc(len + 1);
 		memcpy(user_pass, colon + 1, len);
 		user_pass[len] = '\0';
+		decoded = url_decode(user_pass);
+		free(user_pass);
+		user_pass = decoded;
 	}
 }
 
diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh
index a0564de..8c2ac35 100755
--- a/t/t5550-http-fetch.sh
+++ b/t/t5550-http-fetch.sh
@@ -34,7 +34,7 @@ test_expect_success 'clone http repository' '
 	test_cmp file clone/file
 '
 
-test_expect_failure 'clone http repository with authentication' '
+test_expect_success 'clone http repository with authentication' '
 	mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
 	cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git" &&
 	git clone $AUTH_HTTPD_URL/auth/repo.git clone-auth &&
-- 
1.7.2.3
Previous: Gabriel CoronaNext: Tay Ray Chuan
Message 3 of 4 in “[PATCHv2 0/2] Fix username and password extraction from HTTP URLs”
  1. Gabriel CoronaNov 14, 2010
  2. 1/2 t5550: test HTTP authentication and userinfo decodingGabriel Corona, Nov 14, 2010
  3. 2/2 Fix username and password extraction from HTTP URLsGabriel Corona, Nov 14, 2010
  4. Tay Ray ChuanNov 14, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.