Skip to content

Commit 444c874

Browse files
committed
Add ASCII file name conversion (#17580)
(cherry picked from commit 4590739) (cherry picked from commit 3d1505d)
1 parent 4f3f2ef commit 444c874

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class RequestHandlerSettings
1515
{
1616
internal const bool StaticAddTrailingSlash = true;
1717
internal const string StaticConvertUrlsToAscii = "try";
18+
internal const string StaticConvertFileNamesToAscii = "false";
1819
internal const bool StaticEnableDefaultCharReplacements = true;
1920

2021
internal static readonly CharItem[] DefaultCharCollection =
@@ -73,6 +74,22 @@ public class RequestHandlerSettings
7374
/// </summary>
7475
public bool ShouldTryConvertUrlsToAscii => ConvertUrlsToAscii.InvariantEquals("try");
7576

77+
/// <summary>
78+
/// Gets or sets a value indicating whether to convert file names to ASCII (valid values: "true", "try" or "false").
79+
/// </summary>
80+
[DefaultValue(StaticConvertFileNamesToAscii)]
81+
public string ConvertFileNamesToAscii { get; set; } = StaticConvertFileNamesToAscii;
82+
83+
/// <summary>
84+
/// Gets a value indicating whether URLs should be converted to ASCII.
85+
/// </summary>
86+
public bool ShouldConvertFileNamesToAscii => ConvertFileNamesToAscii.InvariantEquals("true");
87+
88+
/// <summary>
89+
/// Gets a value indicating whether URLs should be tried to be converted to ASCII.
90+
/// </summary>
91+
public bool ShouldTryConvertFileNamesToAscii => ConvertFileNamesToAscii.InvariantEquals("try");
92+
7693
/// <summary>
7794
/// Disable all default character replacements
7895
/// </summary>

src/Umbraco.Core/Strings/DefaultShortStringHelperConfig.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,21 @@ public DefaultShortStringHelperConfig WithDefault(RequestHandlerSettings request
7474
{
7575
urlSegmentConvertTo = CleanStringType.Ascii;
7676
}
77-
78-
if (requestHandlerSettings.ShouldTryConvertUrlsToAscii)
77+
else if (requestHandlerSettings.ShouldTryConvertUrlsToAscii)
7978
{
8079
urlSegmentConvertTo = CleanStringType.TryAscii;
8180
}
8281

82+
CleanStringType fileNameSegmentConvertTo = CleanStringType.Utf8;
83+
if (requestHandlerSettings.ShouldConvertFileNamesToAscii)
84+
{
85+
fileNameSegmentConvertTo = CleanStringType.Ascii;
86+
}
87+
else if (requestHandlerSettings.ShouldTryConvertFileNamesToAscii)
88+
{
89+
fileNameSegmentConvertTo = CleanStringType.TryAscii;
90+
}
91+
8392
return WithConfig(CleanStringType.UrlSegment, new Config
8493
{
8594
PreFilter = ApplyUrlReplaceCharacters,
@@ -92,7 +101,7 @@ public DefaultShortStringHelperConfig WithDefault(RequestHandlerSettings request
92101
{
93102
PreFilter = ApplyUrlReplaceCharacters,
94103
IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_', // letter, digit or underscore
95-
StringType = CleanStringType.Utf8 | CleanStringType.LowerCase,
104+
StringType = fileNameSegmentConvertTo | CleanStringType.LowerCase,
96105
BreakTermsOnUpper = false,
97106
Separator = '-',
98107
}).WithConfig(CleanStringType.Alias, new Config

0 commit comments

Comments
 (0)