All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC] connect.c: Ignore extra colon after hostname
@ 2015-04-07  7:50 Torsten Bögershausen
  2015-04-07 17:57 ` Eric Sunshine
  0 siblings, 1 reply; 2+ messages in thread
From: Torsten Bögershausen @ 2015-04-07  7:50 UTC (permalink / raw)
  To: git; +Cc: tboegi, reidw

Ignore an extra ':' at the end of the hostname in URL's like
"ssh://example.com:/path/to/repo"

The colon is ment 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>
---
Thanks everybody else for comments,
I was especially not aware about the very details in RFC 3986,
and now we should have some TC covering the "now unbroken". 

 connect.c             |  2 ++
 t/t5500-fetch-pack.sh | 17 ++++++++++-------
 t/t5601-clone.sh      | 22 +++++++++++++---------
 3 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/connect.c b/connect.c
index ce0e121..14c924b 100644
--- a/connect.c
+++ b/connect.c
@@ -310,6 +310,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;
 		}
 	}
 }
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 692d717..3a9b775 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -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
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 02b40b1..1f67bdd 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -387,14 +387,18 @@ 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
+test_done
 
 # with port number
 test_expect_success 'clone ssh://host.xz:22/home/user/repo' '
@@ -407,9 +411,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
 	"
-- 
2.2.0.rc1.790.ge19fcd2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH/RFC] connect.c: Ignore extra colon after hostname
  2015-04-07  7:50 [PATCH/RFC] connect.c: Ignore extra colon after hostname Torsten Bögershausen
@ 2015-04-07 17:57 ` Eric Sunshine
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Sunshine @ 2015-04-07 17:57 UTC (permalink / raw)
  To: Torsten Bögershausen; +Cc: Git List, reidw

On Tue, Apr 7, 2015 at 3:50 AM, Torsten Bögershausen <tboegi@web.de> wrote:
> Ignore an extra ':' at the end of the hostname in URL's like
> "ssh://example.com:/path/to/repo"
>
> The colon is ment to separate a port number from the hostname.

s/ment/meant/

More below.

> 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>
> ---
> diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
> index 02b40b1..1f67bdd 100755
> --- a/t/t5601-clone.sh
> +++ b/t/t5601-clone.sh
> @@ -387,14 +387,18 @@ 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
> +test_done

Unwanted test_done crept in?

>  # with port number
>  test_expect_success 'clone ssh://host.xz:22/home/user/repo' '

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-07 17:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-07  7:50 [PATCH/RFC] connect.c: Ignore extra colon after hostname Torsten Bögershausen
2015-04-07 17:57 ` Eric Sunshine

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.