Changed CharCollection input to not special case :
This commit is contained in:
@@ -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<bool?>("Umbraco:CMS:RequestHandler:AddTrailingSlash") ?? true;
|
||||
_configuration.GetValue(Prefix+"AddTrailingSlash", true);
|
||||
|
||||
public bool ConvertUrlsToAscii => _configuration
|
||||
.GetValue<string>("Umbraco:CMS:RequestHandler:ConvertUrlsToAscii").InvariantEquals("true");
|
||||
.GetValue<string>(Prefix+"ConvertUrlsToAscii").InvariantEquals("true");
|
||||
|
||||
public bool TryConvertUrlsToAscii => _configuration
|
||||
.GetValue<string>("Umbraco:CMS:RequestHandler:ConvertUrlsToAscii").InvariantEquals("try");
|
||||
.GetValue<string>(Prefix+"ConvertUrlsToAscii").InvariantEquals("try");
|
||||
|
||||
|
||||
//We need to special handle ":", as this character is special in keys
|
||||
public IEnumerable<IChar> CharCollection => _configuration
|
||||
.GetSection("Umbraco:CMS:RequestHandler:CharCollection")
|
||||
.GetChildren()
|
||||
.Select(kvp => new CharItem
|
||||
public IEnumerable<IChar> 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<string>("Char"),
|
||||
Replacement = x.GetValue<string>("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; }
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
public static partial class Constants
|
||||
{
|
||||
public static class Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Case insensitive prefix for all configurations
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// ":" is used as marker for nested objects in json. E.g. "Umbraco:CMS:" = {"Umbraco":{"CMS":{....}}
|
||||
/// </remarks>
|
||||
public const string ConfigPrefix = "Umbraco:CMS:";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Umbraco.Core
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
public static partial class Constants
|
||||
{
|
||||
|
||||
@@ -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<IRequestHandlerSettings>();
|
||||
|
||||
var y = x.CharCollection;
|
||||
services.AddSingleton(configs);
|
||||
|
||||
return services;
|
||||
|
||||
@@ -14,4 +14,9 @@
|
||||
<Folder Include="wwwroot\Media" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\~\App_Data\TEMP\TypesCache\umbraco-types.DESKTOP-2016.hash" />
|
||||
<_ContentIncludedByDefault Remove="wwwroot\~\App_Data\TEMP\TypesCache\umbraco-types.DESKTOP-2016.list" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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": ""},
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user