Skip to content

Commit 2876789

Browse files
committed
VCST-1527: Incorrect absolute urls resolved by Azure blob assets module (#24)
fix: Incorrect absolute urls resolved by Azure blob assets module
1 parent 4004e7b commit 2876789

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/VirtoCommerce.AzureBlobAssetsModule.Core/AzureBlobProvider.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,16 @@ private static Uri GetAbsoluteUri(Uri baseUri, string inputUrl, string query)
608608
return result;
609609
}
610610

611-
private static Uri GetAbsoluteUri(Uri baseUri, string inputUrl)
611+
public static Uri GetAbsoluteUri(Uri baseUri, string inputUrl)
612612
{
613613
ArgumentNullException.ThrowIfNull(nameof(inputUrl));
614614

615+
// base uri should be end with delimiter. see tests
616+
if (!baseUri.AbsolutePath.EndsWith(Delimiter))
617+
{
618+
baseUri = new Uri(baseUri.AbsoluteUri + Delimiter);
619+
}
620+
615621
// do trim lead slash to prevent transform it to absolute file path on linux.
616622
if (Uri.TryCreate(inputUrl.TrimStart('/'), UriKind.Absolute, out var resultUri))
617623
{

tests/VirtoCommerce.Platform.Assets.AzureBlobStorage.Tests/AzureBlobStorageProviderTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Linq;
23
using Microsoft.Extensions.DependencyInjection;
34
using Microsoft.Extensions.Options;
@@ -130,6 +131,18 @@ public void GetAbsoluteUrlTestWithCdn(string blobKey, string absoluteUrl)
130131
Assert.Equal(absoluteUrl, blobUrlResolver.GetAbsoluteUrl(blobKey));
131132
}
132133

134+
[Theory]
135+
[InlineData("https://qademovc3.core.windows.net/cms", "Themes/", "https://qademovc3.core.windows.net/cms/Themes/")]
136+
[InlineData("https://qademovc3.core.windows.net/cms/", "Themes", "https://qademovc3.core.windows.net/cms/Themes")]
137+
[InlineData("https://qademovc3.core.windows.net/cms/", "/Themes/", "https://qademovc3.core.windows.net/cms/Themes/")]
138+
[InlineData("https://qademovc3.core.windows.net/cms", "/Themes", "https://qademovc3.core.windows.net/cms/Themes")]
139+
[InlineData("https://qademovc3.core.windows.net/", "Themes/", "https://qademovc3.core.windows.net/Themes/")]
140+
[InlineData("https://qademovc3.core.windows.net", "Themes/", "https://qademovc3.core.windows.net/Themes/")]
141+
public void GetAbsoluteUri_StaticMethod(string baseUrl, string inputUrl, string absoluteUrl)
142+
{
143+
Assert.Equal(absoluteUrl, AzureBlobProvider.GetAbsoluteUri(new Uri(baseUrl), inputUrl).AbsoluteUri);
144+
}
145+
133146

134147
private static void ValidateFailure<TOptions>(OptionsValidationException ex, string name = "", int count = 1, params string[] errorsToMatch)
135148
{

0 commit comments

Comments
 (0)