From 01ee495367577a6e7d74e99d1e66e58ccad2eed6 Mon Sep 17 00:00:00 2001 From: Evan Moore Date: Fri, 20 Aug 2021 10:55:09 -0400 Subject: [PATCH] Fix PhysicalFileSystem.GetRelaitvePath for *nix --- src/Umbraco.Core/IO/PhysicalFileSystem.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs index 8c35e80988..db10cae416 100644 --- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs +++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs @@ -258,16 +258,17 @@ namespace Umbraco.Cms.Core.IO // test URL var path = fullPathOrUrl.Replace('\\', '/'); // ensure URL separator char + // if it starts with the root path, strip it and trim the starting slash to make it relative + // eg "c:/websites/test/root/Media/1234/img.jpg" => "1234/img.jpg" + // or on unix systems "/var/wwwroot/test/Meia/1234/img.jpg" + if (_ioHelper.PathStartsWith(path, _rootPathFwd, '/')) + return path.Substring(_rootPathFwd.Length).TrimStart(Constants.CharArrays.ForwardSlash); + // if it starts with the root URL, strip it and trim the starting slash to make it relative // eg "/Media/1234/img.jpg" => "1234/img.jpg" if (_ioHelper.PathStartsWith(path, _rootUrl, '/')) return path.Substring(_rootUrl.Length).TrimStart(Constants.CharArrays.ForwardSlash); - // if it starts with the root path, strip it and trim the starting slash to make it relative - // eg "c:/websites/test/root/Media/1234/img.jpg" => "1234/img.jpg" - if (_ioHelper.PathStartsWith(path, _rootPathFwd, '/')) - return path.Substring(_rootPathFwd.Length).TrimStart(Constants.CharArrays.ForwardSlash); - // unchanged - what else? return path; }