]> git.ipfire.org Git - thirdparty/git.git/commitdiff
connect.c: ignore extra colon after hostname
authorTorsten Bögershausen <tboegi@web.de>
Tue, 7 Apr 2015 20:03:25 +0000 (22:03 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Apr 2015 04:00:53 +0000 (21:00 -0700)
Ignore an extra ':' at the end of the hostname in URL's like
"ssh://example.com:/path/to/repo"

The colon is meant to separate a port number from the hostname.
If the port is empty, the colon should be ignored, see RFC 3986.

It had been working for URLs with ssh:// scheme, but was unintentionally
broken in 86ceb3, "allow ssh://user@[2001:db8::1]/repo.git"

Reported-by: Reid Woodbury Jr. <reidw@rawsound.com>
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
connect.c
t/t5500-fetch-pack.sh
t/t5601-clone.sh

index 84f8156a4c8404613e6c293add8e46ea92f8d5e3..dc31b795e735bdcb47f4c3c54f3236406578aaa0 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -311,6 +311,8 @@ static void get_host_and_port(char **host, const char **port)
                if (end != colon + 1 && *end == '\0' && 0 <= portnr && portnr < 65536) {
                        *colon = 0;
                        *port = colon + 1;
+               } else if (!colon[1]) {
+                       *colon = 0;
                }
        }
 }
index bd37f040b6ce13406ef009944d46d2f1cc6c8d7b..ed404073095ffb607fc6e54d6c92be389dc97bfb 100755 (executable)
@@ -576,13 +576,16 @@ do
        do
                for h in host user@host user@[::1] user@::1
                do
-                       test_expect_success "fetch-pack --diag-url $p://$h/$r" '
-                               check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
-                       '
-                       # "/~" -> "~" conversion
-                       test_expect_success "fetch-pack --diag-url $p://$h/~$r" '
-                               check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
-                       '
+                       for c in "" :
+                       do
+                               test_expect_success "fetch-pack --diag-url $p://$h$c/$r" '
+                                       check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
+                               '
+                               # "/~" -> "~" conversion
+                               test_expect_success "fetch-pack --diag-url $p://$h$c/~$r" '
+                                       check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
+                               '
+                       done
                done
                for h in host User@host User@[::1]
                do
index 02b40b117faa1c6de816001018d1c7deda15ad7d..1befc453a31e6ad67c3805eb94bfe00f6b7a5469 100755 (executable)
@@ -387,14 +387,17 @@ do
 done
 
 #with ssh:// scheme
-test_expect_success 'clone ssh://host.xz/home/user/repo' '
-       test_clone_url "ssh://host.xz/home/user/repo" host.xz "/home/user/repo"
-'
-
-# from home directory
-test_expect_success 'clone ssh://host.xz/~repo' '
-       test_clone_url "ssh://host.xz/~repo" host.xz "~repo"
+#ignore trailing colon
+for tcol in "" :
+do
+       test_expect_success "clone ssh://host.xz$tcol/home/user/repo" '
+               test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo
+       '
+       # from home directory
+       test_expect_success "clone ssh://host.xz$tcol/~repo" '
+       test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo"
 '
+done
 
 # with port number
 test_expect_success 'clone ssh://host.xz:22/home/user/repo' '
@@ -407,9 +410,9 @@ test_expect_success 'clone ssh://host.xz:22/~repo' '
 '
 
 #IPv6
-for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
+for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]:
 do
-       ehost=$(echo $tuah | tr -d "[]")
+       ehost=$(echo $tuah | sed -e "s/1]:/1]/ "| tr -d "[]")
        test_expect_success "clone ssh://$tuah/home/user/repo" "
          test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
        "