Check for relative URIs first

This commit is contained in:
ClemensFischer 2025-09-19 14:06:23 +02:00
parent cd40a627ce
commit f897ce3d36
2 changed files with 17 additions and 5 deletions

View file

@ -46,7 +46,11 @@ namespace MapControl
try
{
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
if (!uri.IsAbsoluteUri)
{
image = await LoadImageAsync(uri.OriginalString);
}
else if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
{
(var buffer, var _) = await GetHttpResponseAsync(uri, progress);
@ -55,9 +59,9 @@ namespace MapControl
image = await LoadImageAsync(buffer);
}
}
else if (uri.IsFile || !uri.IsAbsoluteUri)
else if (uri.IsFile)
{
image = await LoadImageAsync(uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString);
image = await LoadImageAsync(uri.LocalPath);
}
else
{

View file

@ -31,15 +31,23 @@ namespace MapControl
Stream xmlStream;
string defaultUrl = null;
if (uri.IsAbsoluteUri && (uri.Scheme == "http" || uri.Scheme == "https"))
if (!uri.IsAbsoluteUri)
{
xmlStream = File.OpenRead(uri.OriginalString);
}
else if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
{
defaultUrl = uri.OriginalString.Split('?')[0];
xmlStream = await ImageLoader.HttpClient.GetStreamAsync(uri);
}
else if (uri.IsFile)
{
xmlStream = File.OpenRead(uri.LocalPath);
}
else
{
xmlStream = File.OpenRead(uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString);
throw new ArgumentException($"Invalid Capabilities URI: {uri}");
}
using var stream = xmlStream;