Uses URL path separator when generating UDIs for files nested in folders. (#13689)
This commit is contained in:
@@ -232,9 +232,7 @@ public static class UdiGetterExtensions
|
||||
throw new ArgumentNullException("entity");
|
||||
}
|
||||
|
||||
return new StringUdi(
|
||||
Constants.UdiEntityType.Stylesheet,
|
||||
entity.Path.TrimStart(Constants.CharArrays.ForwardSlash)).EnsureClosed();
|
||||
return GetUdiFromPath(Constants.UdiEntityType.Stylesheet, entity.Path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -249,8 +247,15 @@ public static class UdiGetterExtensions
|
||||
throw new ArgumentNullException("entity");
|
||||
}
|
||||
|
||||
return new StringUdi(Constants.UdiEntityType.Script, entity.Path.TrimStart(Constants.CharArrays.ForwardSlash))
|
||||
.EnsureClosed();
|
||||
return GetUdiFromPath(Constants.UdiEntityType.Script, entity.Path);
|
||||
}
|
||||
|
||||
private static StringUdi GetUdiFromPath(string entityType, string path)
|
||||
{
|
||||
var id = path
|
||||
.TrimStart(Constants.CharArrays.ForwardSlash)
|
||||
.Replace("\\", "/");
|
||||
return new StringUdi(entityType, id).EnsureClosed();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -300,7 +305,7 @@ public static class UdiGetterExtensions
|
||||
? Constants.UdiEntityType.PartialViewMacro
|
||||
: Constants.UdiEntityType.PartialView;
|
||||
|
||||
return new StringUdi(entityType, entity.Path.TrimStart(Constants.CharArrays.ForwardSlash)).EnsureClosed();
|
||||
return GetUdiFromPath(entityType, entity.Path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
41
tests/Umbraco.Tests.Common/Builders/PartialViewBuilder.cs
Normal file
41
tests/Umbraco.Tests.Common/Builders/PartialViewBuilder.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Umbraco.Cms.Core.Models;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders;
|
||||
|
||||
public class PartialViewBuilder
|
||||
: BuilderBase<IPartialView>
|
||||
{
|
||||
private string _path;
|
||||
private string _content;
|
||||
private PartialViewType _viewType = PartialViewType.Unknown;
|
||||
|
||||
public PartialViewBuilder WithPath(string path)
|
||||
{
|
||||
_path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PartialViewBuilder WithContent(string content)
|
||||
{
|
||||
_content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PartialViewBuilder WithViewType(PartialViewType viewType)
|
||||
{
|
||||
_viewType = viewType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override IPartialView Build()
|
||||
{
|
||||
var path = _path ?? string.Empty;
|
||||
var content = _content ?? string.Empty;
|
||||
var viewType = _viewType;
|
||||
|
||||
return new PartialView(viewType, path) { Content = content };
|
||||
}
|
||||
}
|
||||
33
tests/Umbraco.Tests.Common/Builders/ScriptBuilder.cs
Normal file
33
tests/Umbraco.Tests.Common/Builders/ScriptBuilder.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Umbraco.Cms.Core.Models;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders;
|
||||
|
||||
public class ScriptBuilder
|
||||
: BuilderBase<Script>
|
||||
{
|
||||
private string _path;
|
||||
private string _content;
|
||||
|
||||
public ScriptBuilder WithPath(string path)
|
||||
{
|
||||
_path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScriptBuilder WithContent(string content)
|
||||
{
|
||||
_content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Script Build()
|
||||
{
|
||||
var path = _path ?? string.Empty;
|
||||
var content = _content ?? string.Empty;
|
||||
|
||||
return new Script(path) { Content = content };
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,8 @@ namespace Umbraco.Cms.Tests.Common.Builders;
|
||||
public class StylesheetBuilder
|
||||
: BuilderBase<Stylesheet>
|
||||
{
|
||||
private string _content;
|
||||
private string _path;
|
||||
private string _content;
|
||||
|
||||
public StylesheetBuilder WithPath(string path)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Extensions;
|
||||
|
||||
[TestFixture]
|
||||
public class UdiGetterExtensionsTests
|
||||
{
|
||||
[TestCase("style.css", "umb://stylesheet/style.css")]
|
||||
[TestCase("editor\\style.css", "umb://stylesheet/editor/style.css")]
|
||||
[TestCase("editor/style.css", "umb://stylesheet/editor/style.css")]
|
||||
public void GetUdiForStylesheet(string path, string expected)
|
||||
{
|
||||
var builder = new StylesheetBuilder();
|
||||
var stylesheet = builder.WithPath(path).Build();
|
||||
var result = stylesheet.GetUdi();
|
||||
Assert.AreEqual(expected, result.ToString());
|
||||
}
|
||||
|
||||
[TestCase("script.js", "umb://script/script.js")]
|
||||
[TestCase("editor\\script.js", "umb://script/editor/script.js")]
|
||||
[TestCase("editor/script.js", "umb://script/editor/script.js")]
|
||||
public void GetUdiForScript(string path, string expected)
|
||||
{
|
||||
var builder = new ScriptBuilder();
|
||||
var script = builder.WithPath(path).Build();
|
||||
var result = script.GetUdi();
|
||||
Assert.AreEqual(expected, result.ToString());
|
||||
}
|
||||
|
||||
[TestCase("test.cshtml", PartialViewType.PartialView, "umb://partial-view/test.cshtml")]
|
||||
[TestCase("editor\\test.cshtml", PartialViewType.PartialView, "umb://partial-view/editor/test.cshtml")]
|
||||
[TestCase("editor/test.cshtml", PartialViewType.PartialView, "umb://partial-view/editor/test.cshtml")]
|
||||
[TestCase("test.cshtml", PartialViewType.PartialViewMacro, "umb://partial-view-macro/test.cshtml")]
|
||||
[TestCase("editor\\test.cshtml", PartialViewType.PartialViewMacro, "umb://partial-view-macro/editor/test.cshtml")]
|
||||
[TestCase("editor/test.cshtml", PartialViewType.PartialViewMacro, "umb://partial-view-macro/editor/test.cshtml")]
|
||||
public void GetUdiForPartialView(string path, PartialViewType viewType, string expected)
|
||||
{
|
||||
var builder = new PartialViewBuilder();
|
||||
var partialView = builder
|
||||
.WithPath(path)
|
||||
.WithViewType(viewType)
|
||||
.Build();
|
||||
var result = partialView.GetUdi();
|
||||
Assert.AreEqual(expected, result.ToString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user