From f897ce3d361aaee00c0e44f73147f114554f1371 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Fri, 19 Sep 2025 14:06:23 +0200 Subject: [PATCH] Check for relative URIs first --- MapControl/Shared/ImageLoader.cs | 10 +++++++--- MapControl/Shared/WmtsCapabilities.cs | 12 ++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/MapControl/Shared/ImageLoader.cs b/MapControl/Shared/ImageLoader.cs index e93efaf5..86e61efd 100644 --- a/MapControl/Shared/ImageLoader.cs +++ b/MapControl/Shared/ImageLoader.cs @@ -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 { diff --git a/MapControl/Shared/WmtsCapabilities.cs b/MapControl/Shared/WmtsCapabilities.cs index c71b344f..2217ee34 100644 --- a/MapControl/Shared/WmtsCapabilities.cs +++ b/MapControl/Shared/WmtsCapabilities.cs @@ -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;