Skip to content

Commit d62c643

Browse files
committed
chore: fix uri parse for images
1 parent a51c3da commit d62c643

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/GZCTF/Models/Internal/Configs.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,16 @@ public class RegistrySet<T> : Dictionary<string, T>
298298
{
299299
public T? GetForImage(string image)
300300
{
301-
if (!Uri.TryCreate(image, UriKind.Absolute, out var uri))
301+
if (string.IsNullOrWhiteSpace(image))
302302
return null;
303303

304-
var host = uri.Host;
305-
if (!uri.IsDefaultPort)
306-
host = $"{host}:{uri.Port}";
304+
image = image.Contains("://") ? image : $"https://{image}";
307305

308-
return TryGetValue(host, out var config) ? config : null;
306+
if (!Uri.TryCreate(image, UriKind.Absolute, out var uri) || uri.HostNameType == UriHostNameType.Unknown)
307+
return null;
308+
309+
return TryGetValue(uri.Authority, out var cfg) ? cfg :
310+
TryGetValue(uri.Host, out var cfgHost) ? cfgHost : null;
309311
}
310312
}
311313

0 commit comments

Comments
 (0)