From 77b56a21787505a1b22692cdc1ba15a6d916952f Mon Sep 17 00:00:00 2001 From: kevin <5299031+kevin9327@users.noreply.github.com> Date: Mon, 2 Nov 2026 23:22:43 +0900 Subject: [PATCH] fix(url): keep capitalized mailto: and tel: links as they are (#7052) EnsureURLScheme matched the mailto: and tel: prefixes case-sensitively, so a support link typed as Mailto: or TEL: (phone keyboards capitalize the first letter) got https:// prepended and opened a broken web page. URL schemes are case-insensitive, and the check now is too. --- internal/util/common/url.go | 7 +++++-- internal/util/common/url_test.go | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/util/common/url.go b/internal/util/common/url.go index 13a71323b..c6cb2e4b8 100644 --- a/internal/util/common/url.go +++ b/internal/util/common/url.go @@ -16,9 +16,12 @@ func EnsureURLScheme(raw string) string { if trimmed == "" { return "" } + // Schemes are case-insensitive (RFC 3986), and phone keyboards often + // capitalize the first letter ("Mailto:", "Tel:"). + lower := strings.ToLower(trimmed) if strings.Contains(trimmed, "://") || - strings.HasPrefix(trimmed, "mailto:") || - strings.HasPrefix(trimmed, "tel:") { + strings.HasPrefix(lower, "mailto:") || + strings.HasPrefix(lower, "tel:") { return trimmed } return "https://" + trimmed diff --git a/internal/util/common/url_test.go b/internal/util/common/url_test.go index 167ff6650..2d182294a 100644 --- a/internal/util/common/url_test.go +++ b/internal/util/common/url_test.go @@ -18,6 +18,8 @@ func TestEnsureURLScheme(t *testing.T) { {"mailto", "mailto:support@example.com", "mailto:support@example.com"}, {"tel", "tel:+1234567890", "tel:+1234567890"}, {"trims whitespace", " t.me/xui_support ", "https://t.me/xui_support"}, + {"capitalized mailto", "Mailto:support@example.com", "Mailto:support@example.com"}, + {"uppercase tel", "TEL:+1234567890", "TEL:+1234567890"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {