All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Fabian Pottbäcker" <fpottbaecker+git@mailbox.org>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Patrick Steinhardt" <ps@pks.im>,
	"Fabian Pottbäcker" <fpottbaecker+git@mailbox.org>
Subject: [PATCH 1/3] urlmatch: normalize ssh and ftp default ports
Date: Fri, 24 Jul 2026 02:40:09 +0200	[thread overview]
Message-ID: <20260724004011.41795-2-fpottbaecker+git@mailbox.org> (raw)
In-Reply-To: <20260724004011.41795-1-fpottbaecker+git@mailbox.org>

These protocols are still supported by git and have well known
default ports. This leaves FTPS, which does not have one default
port.

Signed-off-by: Fabian Pottbäcker <fpottbaecker+git@mailbox.org>
---
 t/unit-tests/u-urlmatch-normalization.c |  9 +++++++++
 urlmatch.c                              | 16 ++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/t/unit-tests/u-urlmatch-normalization.c b/t/unit-tests/u-urlmatch-normalization.c
index 3595d893a2..1808e5e51f 100644
--- a/t/unit-tests/u-urlmatch-normalization.c
+++ b/t/unit-tests/u-urlmatch-normalization.c
@@ -141,9 +141,18 @@ void test_urlmatch_normalization__port_normalization(void)
 	check_normalized_url("http://x:80", "http://x/");
 	check_normalized_url("http://x:080", "http://x/");
 	check_normalized_url("http://x:000000080", "http://x/");
+	check_normalized_url("https://x:8443", "https://x:8443/");
 	check_normalized_url("https://x:443", "https://x/");
 	check_normalized_url("https://x:0443", "https://x/");
 	check_normalized_url("https://x:000000443", "https://x/");
+	check_normalized_url("ftp://x:2121", "ftp://x:2121/");
+	check_normalized_url("ftp://x:21", "ftp://x/");
+	check_normalized_url("ftp://x:021", "ftp://x/");
+	check_normalized_url("ftp://x:00000021", "ftp://x/");
+	check_normalized_url("ssh://x:2222", "ssh://x:2222/");
+	check_normalized_url("ssh://x:22", "ssh://x/");
+	check_normalized_url("ssh://x:022", "ssh://x/");
+	check_normalized_url("ssh://x:00000022", "ssh://x/");
 }
 
 void test_urlmatch_normalization__general_escape(void)
diff --git a/urlmatch.c b/urlmatch.c
index 20bc2d009c..0c2ddf2e40 100644
--- a/urlmatch.c
+++ b/urlmatch.c
@@ -274,12 +274,20 @@ static char *url_normalize_1(const char *url, struct url_info *out_info, bool al
 		if (url == slash_ptr) {
 			/* Skip ":" port with no number, it's same as default */
 		} else if (slash_ptr - url == 2 &&
-			   starts_with(norm.buf, "http:") &&
-			   !strncmp(url, "80", 2)) {
+			    starts_with(norm.buf, "ftp:") &&
+			    !strncmp(url, "21", 2)) {
+			/* Skip http :21 as it's the default */
+		} else if (slash_ptr - url == 2 &&
+			    starts_with(norm.buf, "ssh:") &&
+			    !strncmp(url, "22", 2)) {
+			/* Skip http :22 as it's the default */
+		} else if (slash_ptr - url == 2 &&
+			    starts_with(norm.buf, "http:") &&
+			    !strncmp(url, "80", 2)) {
 			/* Skip http :80 as it's the default */
 		} else if (slash_ptr - url == 3 &&
-			   starts_with(norm.buf, "https:") &&
-			   !strncmp(url, "443", 3)) {
+			    starts_with(norm.buf, "https:") &&
+			    !strncmp(url, "443", 3)) {
 			/* Skip https :443 as it's the default */
 		} else {
 			/*
-- 
2.50.1 (Apple Git-155)


  reply	other threads:[~2026-07-24  0:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  0:40 [PATCH 0/3] config: support scp-style --url Fabian Pottbäcker
2026-07-24  0:40 ` Fabian Pottbäcker [this message]
2026-07-24 11:35   ` [PATCH 1/3] urlmatch: normalize ssh and ftp default ports Ben Knoble
2026-07-24  0:40 ` [PATCH 2/3] t1300: cover --url for some --get-urlmatch tests Fabian Pottbäcker
2026-07-24  0:40 ` [PATCH 3/3] config: use url_parse for --url Fabian Pottbäcker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724004011.41795-2-fpottbaecker+git@mailbox.org \
    --to=fpottbaecker+git@mailbox.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.