Adding checks for subscription url

This commit is contained in:
2dust
2024-10-24 17:09:07 +08:00
parent 3fafc6de93
commit 34f5c0f910
11 changed files with 69 additions and 34 deletions

View File

@@ -10,7 +10,8 @@
ConfigType = EConfigType.Hysteria2
};
Uri url = new(str);
var url = Utils.TryUri(str);
if (url == null) return null;
item.Address = url.IdnHost;
item.Port = url.Port;

View File

@@ -81,15 +81,9 @@ namespace ServiceLib.Handler.Fmt
private static ProfileItem? ResolveSip002(string result)
{
Uri parsedUrl;
try
{
parsedUrl = new Uri(result);
}
catch (UriFormatException)
{
return null;
}
var parsedUrl = Utils.TryUri(result);
if (parsedUrl == null) return null;
ProfileItem item = new()
{
Remarks = parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped),

View File

@@ -93,15 +93,9 @@
private static ProfileItem? ResolveSocksNew(string result)
{
Uri parsedUrl;
try
{
parsedUrl = new Uri(result);
}
catch (UriFormatException)
{
return null;
}
var parsedUrl = Utils.TryUri(result);
if (parsedUrl == null) return null;
ProfileItem item = new()
{
Remarks = parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped),

View File

@@ -10,8 +10,9 @@
{
ConfigType = EConfigType.Trojan
};
Uri url = new(str);
var url = Utils.TryUri(str);
if (url == null) return null;
item.Address = url.IdnHost;
item.Port = url.Port;

View File

@@ -11,7 +11,8 @@
ConfigType = EConfigType.TUIC
};
Uri url = new(str);
var url = Utils.TryUri(str);
if (url == null) return null;
item.Address = url.IdnHost;
item.Port = url.Port;

View File

@@ -12,7 +12,8 @@
Security = Global.None
};
Uri url = new(str);
var url = Utils.TryUri(str);
if (url == null) return null;
item.Address = url.IdnHost;
item.Port = url.Port;

View File

@@ -105,7 +105,8 @@
Security = "auto"
};
Uri url = new(str);
var url = Utils.TryUri(str);
if (url == null) return null;
item.Address = url.IdnHost;
item.Port = url.Port;

View File

@@ -11,7 +11,8 @@
ConfigType = EConfigType.WireGuard
};
Uri url = new(str);
var url = Utils.TryUri(str);
if (url == null) return null;
item.Address = url.IdnHost;
item.Port = url.Port;