From 9ee6bcd398057cb0cf3c52b9dc93b094d3d37235 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Thu, 8 Apr 2010 10:15:16 +0800 Subject: t5541-http-push: add test for URLs with trailing slash Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index 53f54a2..7873d94 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -34,8 +34,34 @@ test_expect_success 'setup remote repository' ' mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" ' -test_expect_success 'clone remote repository' ' +cat >exp <act <"$HTTPD_ROOT_PATH"/access.log && + + # Clear the log, so that it does not affect the "used receive-pack + # service" test which reads the log too. + # + # We do this before the actual comparison to ensure the log is cleared. + echo > "$HTTPD_ROOT_PATH"/access.log && + + test_cmp exp act +' + +test_expect_success 'clone remote repository' ' + rm -rf test_repo_clone && git clone $HTTPD_URL/smart/test_repo.git test_repo_clone ' @@ -68,6 +94,7 @@ test_expect_success 'create and delete remote branch' ' ' cat >exp < Date: Thu, 8 Apr 2010 10:15:17 +0800 Subject: http: make end_url_with_slash() public Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano diff --git a/http.c b/http.c index deab595..163c0e4 100644 --- a/http.c +++ b/http.c @@ -720,7 +720,7 @@ static inline int hex(int v) return 'A' + v - 10; } -static void end_url_with_slash(struct strbuf *buf, const char *url) +void end_url_with_slash(struct strbuf *buf, const char *url) { strbuf_addstr(buf, url); if (buf->len && buf->buf[buf->len - 1] != '/') diff --git a/http.h b/http.h index 5c9441c..c78cacb 100644 --- a/http.h +++ b/http.h @@ -117,6 +117,7 @@ extern void append_remote_object_url(struct strbuf *buf, const char *url, int only_two_digit_prefix); extern char *get_remote_object_url(const char *url, const char *hex, int only_two_digit_prefix); +extern void end_url_with_slash(struct strbuf *buf, const char *url); /* Options for http_request_*() */ #define HTTP_NO_CACHE 1 -- cgit v0.10.2-6-g49f6 From d8fab07208abfbe7dc93aea97c5577cdd73266c5 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Thu, 8 Apr 2010 10:15:18 +0800 Subject: remote-curl: ensure that URLs have a trailing slash Previously, we blindly assumed that URLs passed to the remote-curl helper did not end with a trailing slash. Use the convenience function end_url_with_slash() from http.[ch] to ensure that URLs have a trailing slash on invocation of the remote-curl helper, and use the URL as one with a trailing slash throughout. It is possible for users to pass a URL with a trailing slash to remote-curl, by, say, setting it in remote..url in their git config. The resulting requests have an empty path component (//) and may break implementations of the http git protocol. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano diff --git a/remote-curl.c b/remote-curl.c index a904164..1fe59d6 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -9,7 +9,7 @@ #include "sideband.h" static struct remote *remote; -static const char *url; +static const char *url; /* always ends with a trailing slash */ static struct walker *walker; struct options { @@ -108,7 +108,7 @@ static struct discovery* discover_refs(const char *service) return last; free_discovery(last); - strbuf_addf(&buffer, "%s/info/refs", url); + strbuf_addf(&buffer, "%sinfo/refs", url); if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) { is_http = 1; if (!strchr(url, '?')) @@ -128,7 +128,7 @@ static struct discovery* discover_refs(const char *service) strbuf_reset(&buffer); proto_git_candidate = 0; - strbuf_addf(&buffer, "%s/info/refs", url); + strbuf_addf(&buffer, "%sinfo/refs", url); refs_url = strbuf_detach(&buffer, NULL); http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE); @@ -518,7 +518,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads) rpc->out = client.out; strbuf_init(&rpc->result, 0); - strbuf_addf(&buf, "%s/%s", url, svc); + strbuf_addf(&buf, "%s%s", url, svc); rpc->service_url = strbuf_detach(&buf, NULL); strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc); @@ -805,11 +805,13 @@ int main(int argc, const char **argv) remote = remote_get(argv[1]); if (argc > 2) { - url = argv[2]; + end_url_with_slash(&buf, argv[2]); } else { - url = remote->url[0]; + end_url_with_slash(&buf, remote->url[0]); } + url = strbuf_detach(&buf, NULL); + do { if (strbuf_getline(&buf, stdin, '\n') == EOF) break; diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index 7873d94..f0c50d3 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -38,7 +38,7 @@ cat >exp <