fix(fmt): default the AnyTLS and Naive port to 443 when the link omits it (#10504)

The AnyTLS URI scheme makes the port optional and defaults it to 443,
and two of its three examples leave it out. The naive+https:// and
naive+quic:// link format does the same: the port is omitted when it is
443, and none of its examples carries one.

System.Uri answers -1 for an unregistered scheme with no port, so these
links were imported with Port = -1 and the profile failed IsValid().
Apply the same default Hysteria2Fmt already uses (#10026). An explicit
":0" is still kept as 0.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Wei-Lun Li
2026-11-03 20:44:03 +09:00
committed by GitHub
parent fe54a73d74
commit ff9fd7b988
4 changed files with 99 additions and 2 deletions
+4 -1
View File
@@ -17,7 +17,10 @@ public class AnytlsFmt : BaseFmt
ConfigType = EConfigType.Anytls,
Remarks = parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped),
Address = parsedUrl.IdnHost,
Port = parsedUrl.Port,
// The URI scheme makes the port optional and defaults it to 443
// (https://github.com/anytls/anytls-go/blob/main/docs/uri_scheme.md). Uri.Port answers
// -1 for an unregistered scheme carrying no port; an explicit ":0" stays 0.
Port = parsedUrl.Port == -1 ? 443 : parsedUrl.Port,
};
var rawUserInfo = Utils.UrlDecode(parsedUrl.UserInfo);
item.Password = rawUserInfo;
+4 -1
View File
@@ -17,7 +17,10 @@ public class NaiveFmt : BaseFmt
ConfigType = EConfigType.Naive,
Remarks = parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped),
Address = parsedUrl.IdnHost,
Port = parsedUrl.Port,
// naive+https:// and naive+quic:// links leave the port out when it is 443
// (https://gist.github.com/DuckSoft/ca03913b0a26fc77a1da4d01cc6ab2f1). Uri.Port answers
// -1 for an unregistered scheme carrying no port; an explicit ":0" stays 0.
Port = parsedUrl.Port == -1 ? 443 : parsedUrl.Port,
};
var protocolExtra = item.GetProtocolExtra();
if (parsedUrl.Scheme.Contains("quic"))