Add ASCII file name conversion (#17580)
(cherry picked from commit4590739fa5) (cherry picked from commit3d1505d4c6)
This commit is contained in:
@@ -15,6 +15,7 @@ public class RequestHandlerSettings
|
||||
{
|
||||
internal const bool StaticAddTrailingSlash = true;
|
||||
internal const string StaticConvertUrlsToAscii = "try";
|
||||
internal const string StaticConvertFileNamesToAscii = "false";
|
||||
internal const bool StaticEnableDefaultCharReplacements = true;
|
||||
|
||||
internal static readonly CharItem[] DefaultCharCollection =
|
||||
@@ -73,6 +74,22 @@ public class RequestHandlerSettings
|
||||
/// </summary>
|
||||
public bool ShouldTryConvertUrlsToAscii => ConvertUrlsToAscii.InvariantEquals("try");
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to convert file names to ASCII (valid values: "true", "try" or "false").
|
||||
/// </summary>
|
||||
[DefaultValue(StaticConvertFileNamesToAscii)]
|
||||
public string ConvertFileNamesToAscii { get; set; } = StaticConvertFileNamesToAscii;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether URLs should be converted to ASCII.
|
||||
/// </summary>
|
||||
public bool ShouldConvertFileNamesToAscii => ConvertFileNamesToAscii.InvariantEquals("true");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether URLs should be tried to be converted to ASCII.
|
||||
/// </summary>
|
||||
public bool ShouldTryConvertFileNamesToAscii => ConvertFileNamesToAscii.InvariantEquals("try");
|
||||
|
||||
/// <summary>
|
||||
/// Disable all default character replacements
|
||||
/// </summary>
|
||||
|
||||
@@ -74,12 +74,21 @@ public class DefaultShortStringHelperConfig
|
||||
{
|
||||
urlSegmentConvertTo = CleanStringType.Ascii;
|
||||
}
|
||||
|
||||
if (requestHandlerSettings.ShouldTryConvertUrlsToAscii)
|
||||
else if (requestHandlerSettings.ShouldTryConvertUrlsToAscii)
|
||||
{
|
||||
urlSegmentConvertTo = CleanStringType.TryAscii;
|
||||
}
|
||||
|
||||
CleanStringType fileNameSegmentConvertTo = CleanStringType.Utf8;
|
||||
if (requestHandlerSettings.ShouldConvertFileNamesToAscii)
|
||||
{
|
||||
fileNameSegmentConvertTo = CleanStringType.Ascii;
|
||||
}
|
||||
else if (requestHandlerSettings.ShouldTryConvertFileNamesToAscii)
|
||||
{
|
||||
fileNameSegmentConvertTo = CleanStringType.TryAscii;
|
||||
}
|
||||
|
||||
return WithConfig(CleanStringType.UrlSegment, new Config
|
||||
{
|
||||
PreFilter = ApplyUrlReplaceCharacters,
|
||||
@@ -92,7 +101,7 @@ public class DefaultShortStringHelperConfig
|
||||
{
|
||||
PreFilter = ApplyUrlReplaceCharacters,
|
||||
IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_', // letter, digit or underscore
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.LowerCase,
|
||||
StringType = fileNameSegmentConvertTo | CleanStringType.LowerCase,
|
||||
BreakTermsOnUpper = false,
|
||||
Separator = '-',
|
||||
}).WithConfig(CleanStringType.Alias, new Config
|
||||
|
||||
Reference in New Issue
Block a user