Skip to content

Commit 15b9110

Browse files
Merge pull request #84 from umbraco-community/bugifx/image-with-file-prefix
Bugfix for relative URLs to not use file:// - Cherry picked/back ported
2 parents 6d28ce2 + de7fd82 commit 15b9110

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Our.Umbraco.TagHelpers/ImgTagHelper.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,19 +451,25 @@ private string GetImageAltText(IPublishedContent image)
451451
private string AddQueryToUrl(string url, string key, string value)
452452
{
453453
Uri uri = null!;
454+
bool isRelativeUrl = false;
455+
454456
if (url.Contains("://"))
455457
{
456458
uri = new Uri(url);
457459
}
458460
else
459461
{
462+
isRelativeUrl = true;
460463
if (!Uri.TryCreate(url, UriKind.Absolute, out uri!))
461464
uri = new Uri(new Uri(Request.GetDisplayUrl()), url);
462465
}
463466

464467
if (uri == null) return url;
465468

466-
var baseUri = uri.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.UriEscaped);
469+
var baseUri = isRelativeUrl
470+
? uri.GetComponents(UriComponents.Path, UriFormat.UriEscaped)
471+
: uri.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.UriEscaped);
472+
467473
var query = QueryHelpers.ParseQuery(uri.Query);
468474

469475
var items = query.SelectMany(x => x.Value, (col, value) => new KeyValuePair<string, string>(col.Key, value)).ToList();

0 commit comments

Comments
 (0)