mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-05 20:34:20 +00:00
fb3a1559b2
A support URL saved without a scheme (e.g. "t.me/handle") is served verbatim in the subscription Support-Url header and page data, and client apps resolve it relative to the subscription domain — clicking it lands on "https://panel.example/t.me/handle". Same hazard for the profile URL. Default the scheme to https:// when none is present, both when saving the settings and when reading already-stored values, so existing databases are covered without a migration. Deliberate non-http schemes (tg://, mailto:, tel:) pass through untouched, which is why these two fields don't go through SanitizeHTTPURL's http(s)-only validation. Closes #5738
30 lines
995 B
Go
30 lines
995 B
Go
package common
|
|
|
|
import "testing"
|
|
|
|
func TestEnsureURLScheme(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{"empty", "", ""},
|
|
{"whitespace only", " ", ""},
|
|
{"bare telegram handle", "t.me/xui_support", "https://t.me/xui_support"},
|
|
{"bare domain with path", "example.com/help", "https://example.com/help"},
|
|
{"already https", "https://t.me/xui_support", "https://t.me/xui_support"},
|
|
{"already http", "http://example.com", "http://example.com"},
|
|
{"telegram deep link", "tg://resolve?domain=xui_support", "tg://resolve?domain=xui_support"},
|
|
{"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"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := EnsureURLScheme(tt.in); got != tt.want {
|
|
t.Errorf("EnsureURLScheme(%q) = %q, want %q", tt.in, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|