From b93b4f7c4f526d10a41abcd5eae8c35dc5421bfe Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 19 Mar 2020 18:43:39 +0100 Subject: [PATCH] Changed CharCollection input to not special case : --- .../Models/RequestHandlerSettings.cs | 70 +++++++++++++++---- src/Umbraco.Core/Constants-Configuration.cs | 16 +++++ src/Umbraco.Core/Constants-System.cs | 2 +- ...coBackOfficeServiceCollectionExtensions.cs | 5 ++ .../Umbraco.Web.UI.NetCore.csproj | 5 ++ src/Umbraco.Web.UI.NetCore/appsettings.json | 38 ++++------ src/Umbraco.Web/Runtime/WebInitialComposer.cs | 1 - 7 files changed, 94 insertions(+), 43 deletions(-) create mode 100644 src/Umbraco.Core/Constants-Configuration.cs diff --git a/src/Umbraco.Configuration/Models/RequestHandlerSettings.cs b/src/Umbraco.Configuration/Models/RequestHandlerSettings.cs index e0804abd0e..784147af07 100644 --- a/src/Umbraco.Configuration/Models/RequestHandlerSettings.cs +++ b/src/Umbraco.Configuration/Models/RequestHandlerSettings.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Configuration; using Umbraco.Core; @@ -8,6 +9,35 @@ namespace Umbraco.Configuration.Models { internal class RequestHandlerSettings : IRequestHandlerSettings { + private const string Prefix = Constants.Configuration.ConfigPrefix + "RequestHandler:"; + private static readonly CharItem[] DefaultCharCollection = + { + new CharItem { Char = " ", Replacement = "-" }, + new CharItem { Char = "\"", Replacement = "" }, + new CharItem { Char = "'", Replacement = "" }, + new CharItem { Char = "%", Replacement = "" }, + new CharItem { Char = ".", Replacement = "" }, + new CharItem { Char = ";", Replacement = "" }, + new CharItem { Char = "/", Replacement = "" }, + new CharItem { Char = "\\", Replacement = "" }, + new CharItem { Char = ":", Replacement = "" }, + new CharItem { Char = "#", Replacement = "" }, + new CharItem { Char = "+", Replacement = "plus" }, + new CharItem { Char = "*", Replacement = "star" }, + new CharItem { Char = "&", Replacement = "" }, + new CharItem { Char = "?", Replacement = "" }, + new CharItem { Char = "æ", Replacement = "ae" }, + new CharItem { Char = "ä", Replacement = "ae" }, + new CharItem { Char = "ø", Replacement = "oe" }, + new CharItem { Char = "ö", Replacement = "oe" }, + new CharItem { Char = "å", Replacement = "aa" }, + new CharItem { Char = "ü", Replacement = "ue" }, + new CharItem { Char = "ß", Replacement = "ss" }, + new CharItem { Char = "|", Replacement = "-" }, + new CharItem { Char = "<", Replacement = "" }, + new CharItem { Char = ">", Replacement = "" } + }; + private readonly IConfiguration _configuration; public RequestHandlerSettings(IConfiguration configuration) @@ -16,29 +46,39 @@ namespace Umbraco.Configuration.Models } public bool AddTrailingSlash => - _configuration.GetValue("Umbraco:CMS:RequestHandler:AddTrailingSlash") ?? true; + _configuration.GetValue(Prefix+"AddTrailingSlash", true); public bool ConvertUrlsToAscii => _configuration - .GetValue("Umbraco:CMS:RequestHandler:ConvertUrlsToAscii").InvariantEquals("true"); + .GetValue(Prefix+"ConvertUrlsToAscii").InvariantEquals("true"); public bool TryConvertUrlsToAscii => _configuration - .GetValue("Umbraco:CMS:RequestHandler:ConvertUrlsToAscii").InvariantEquals("try"); + .GetValue(Prefix+"ConvertUrlsToAscii").InvariantEquals("try"); //We need to special handle ":", as this character is special in keys - public IEnumerable CharCollection => _configuration - .GetSection("Umbraco:CMS:RequestHandler:CharCollection") - .GetChildren() - .Select(kvp => new CharItem + public IEnumerable CharCollection + { + get { - Char = kvp.Key, - Replacement = kvp.Value - }).Union(new[] - { - new CharItem { Char = ":", Replacement = string.Empty } - }); + var collection = _configuration.GetSection(Prefix + "CharCollection").GetChildren() + .Select(x => new CharItem() + { + Char = x.GetValue("Char"), + Replacement = x.GetValue("Replacement"),UseLegacyEncoding + }).ToArray(); - private class CharItem : IChar + if (collection.Any() || _configuration.GetSection("Prefix").GetChildren().Any(x => + x.Key.Equals("CharCollection", StringComparison.OrdinalIgnoreCase))) + { + return collection; + } + + return DefaultCharCollection; + } + } + + + public class CharItem : IChar { public string Char { get; set; } public string Replacement { get; set; } diff --git a/src/Umbraco.Core/Constants-Configuration.cs b/src/Umbraco.Core/Constants-Configuration.cs new file mode 100644 index 0000000000..b3d9e52d63 --- /dev/null +++ b/src/Umbraco.Core/Constants-Configuration.cs @@ -0,0 +1,16 @@ +namespace Umbraco.Core +{ + public static partial class Constants + { + public static class Configuration + { + /// + /// Case insensitive prefix for all configurations + /// + /// + /// ":" is used as marker for nested objects in json. E.g. "Umbraco:CMS:" = {"Umbraco":{"CMS":{....}} + /// + public const string ConfigPrefix = "Umbraco:CMS:"; + } + } +} diff --git a/src/Umbraco.Core/Constants-System.cs b/src/Umbraco.Core/Constants-System.cs index abb92298f4..837db01b63 100644 --- a/src/Umbraco.Core/Constants-System.cs +++ b/src/Umbraco.Core/Constants-System.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Core + namespace Umbraco.Core { public static partial class Constants { diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs index 334e992617..9f9250e309 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs @@ -8,6 +8,7 @@ using Umbraco.Configuration; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; @@ -23,6 +24,10 @@ namespace Umbraco.Web.BackOffice.AspNetCore var configsFactory = new AspNetCoreConfigsFactory(configuration); var configs = configsFactory.Create(); + + var x = configs.GetConfig(); + + var y = x.CharCollection; services.AddSingleton(configs); return services; diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj index 69d223bcc6..ca7c3e26fa 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj +++ b/src/Umbraco.Web.UI.NetCore/Umbraco.Web.UI.NetCore.csproj @@ -14,4 +14,9 @@ + + <_ContentIncludedByDefault Remove="wwwroot\~\App_Data\TEMP\TypesCache\umbraco-types.DESKTOP-2016.hash" /> + <_ContentIncludedByDefault Remove="wwwroot\~\App_Data\TEMP\TypesCache\umbraco-types.DESKTOP-2016.list" /> + + diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index de282cf66b..1c89647efa 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -71,32 +71,18 @@ }, "RequestHandler": { "AddTrailingSlash": true, - "CharCollection": { - " ": "-", - "\"": "", - "'": "", - "%": "", - ".": "", - ";": "", - "/": "", - "\\": "", - ":": "", - "#": "", - "+": "plus", - "*": "star", - "&": "", - "?": "", - "æ": "ae", - "ø": "oe", - "å": "aa", - "ä": "ae", - "ö": "oe", - "ü": "ue", - "ß": "ss", - "|": "-", - "<": "", - ">": "" - } + "CharCollection": [ + {"Char": " ", "Replacement": "-"}, + {"Char": "\"", "Replacement": ""}, + {"Char": "'", "Replacement": ""}, + {"Char": "%", "Replacement": ""}, + {"Char": ".", "Replacement": ""}, + {"Char": ";", "Replacement": ""}, + {"Char": "/", "Replacement": ""}, + {"Char": "\\", "Replacement": ""}, + {"Char": ":", "Replacement": ""}, + + ] } } } diff --git a/src/Umbraco.Web/Runtime/WebInitialComposer.cs b/src/Umbraco.Web/Runtime/WebInitialComposer.cs index c1cf76d168..b81cafdb40 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComposer.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComposer.cs @@ -43,7 +43,6 @@ using Umbraco.Web.SignalR; using Umbraco.Web.Templates; using Umbraco.Web.Trees; using Umbraco.Web.WebApi; -using Current = Umbraco.Web.Composing.Current; using Umbraco.Web.PropertyEditors; using Umbraco.Examine; using Umbraco.Core.Models;