Skip to content

Commit 8f8ce6a

Browse files
committed
Features.UI: Fixed issue with the BetterImageGallery image handler
1 parent 5df77cb commit 8f8ce6a

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

Web/Components/LinkBuilder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public LinkBuilder(string url, bool includeSiteRoot = true)
4444
(_, siteRootPaths) = ParsePath(siteRootUri.AbsolutePath);
4545
}
4646

47+
if (!includeSiteRoot)
48+
{
49+
urlAuthority = string.Empty;
50+
}
51+
4752
var cleanUrl = CombinePaths(urlAuthority, [.. siteRootPaths, .. urlPaths]);
4853

4954
_uri = new(cleanUrl, UriKind.RelativeOrAbsolute);
@@ -304,6 +309,10 @@ private static (string, string[]) ParsePath(string path)
304309
{
305310
var urlBase = string.Empty;
306311

312+
path = path
313+
.Replace("../", string.Empty)
314+
.Replace("..\\", string.Empty);
315+
307316
// double leading slashes causes Uri to create a file URI e.g.: "file://something", so trim leading slashes
308317
if (Uri.TryCreate(path.TrimStart('/'), UriKind.Absolute, out var uri))
309318
{

mojoPortal.Features.UI/BetterImageGallery/BetterImageGalleryController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public IHttpActionResult GetItems([FromUri] string path, int moduleId = -1)
2222
[Route("api/BetterImageGallery/imagehandler")]
2323
public IHttpActionResult ImageHandler([FromUri] string path)
2424
{
25-
var imgPath = HttpContext.Current.Server.MapPath("~/Data/systemfiles/BetterImageGalleryCache/" + path);
25+
var imgPath = HttpContext.Current.Server.MapPath($"~/Data/systemfiles/BetterImageGalleryCache/{path.ToLinkBuilder(false)}");
2626
var fileInfo = new FileInfo(imgPath);
2727

2828
return !fileInfo.Exists

mojoPortal.Features.UI/BetterImageGallery/LayoutSelector.ascx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private void EnsureItems()
4848
}
4949

5050
if (ddlLayouts.Items.Count > 0) return;
51-
string skinThemesPath = SiteUtils.DetermineSkinBaseUrl(true, Page) + themesPath;
51+
string skinThemesPath = new Uri(SiteUtils.DetermineSkinBaseUrl(true, Page) + themesPath,UriKind.Absolute).AbsolutePath;
5252

5353
List<FileInfo> themeFiles = GetLayouts(skinThemesPath);
5454
List<ListItem> items = new List<ListItem>();

0 commit comments

Comments
 (0)