Browse Source

Use InvariantCulture for ToLower and Regex.

pull/5416/head
maliming 6 years ago
parent
commit
bc5da1f722
  1. 52
      framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs
  2. 51
      framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs
  3. 51
      framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs
  4. 19
      framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobNamingNormalizer.cs
  5. 51
      framework/src/Volo.Abp.BlobStoring.Minio/Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs

52
framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs

@ -1,47 +1,51 @@
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
namespace Volo.Abp.BlobStoring.Aliyun namespace Volo.Abp.BlobStoring.Aliyun
{ {
public class AliyunBlobNamingNormalizer : IBlobNamingNormalizer, ITransientDependency public class AliyunBlobNamingNormalizer : IBlobNamingNormalizer, ITransientDependency
{ {
/// <summary> /// <summary>
/// Container names can contain only letters, numbers, and the dash (-) character /// Container names can contain only letters, numbers, and the dash (-) character
/// they can't start or end with the dash (-) character /// they can't start or end with the dash (-) character
/// Container names must be from 3 through 63 characters long /// Container names must be from 3 through 63 characters long
/// </summary> /// </summary>
public virtual string NormalizeContainerName(string containerName) public virtual string NormalizeContainerName(string containerName)
{ {
// All letters in a container name must be lowercase. using (CultureHelper.Use(CultureInfo.InvariantCulture))
containerName = containerName.ToLowerInvariant(); {
// All letters in a container name must be lowercase.
containerName = containerName.ToLower();
// Container names can contain only letters, numbers, and the dash (-) character. // Container names can contain only letters, numbers, and the dash (-) character.
containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty);
// Every dash (-) character must be immediately preceded and followed by a letter or number; // Every dash (-) character must be immediately preceded and followed by a letter or number;
// consecutive dashes are not permitted in container names. // consecutive dashes are not permitted in container names.
// Container names must start or end with a letter or number // Container names must start or end with a letter or number
containerName = Regex.Replace(containerName, "-{2,}", "-"); containerName = Regex.Replace(containerName, "-{2,}", "-");
containerName = Regex.Replace(containerName, "^-", string.Empty); containerName = Regex.Replace(containerName, "^-", string.Empty);
containerName = Regex.Replace(containerName, "-$", string.Empty); containerName = Regex.Replace(containerName, "-$", string.Empty);
// Container names must be from 3 through 63 characters long. // Container names must be from 3 through 63 characters long.
if (containerName.Length < 3) if (containerName.Length < 3)
{
var length = containerName.Length;
for (var i = 0; i < 3 - length; i++)
{ {
containerName += "0"; var length = containerName.Length;
for (var i = 0; i < 3 - length; i++)
{
containerName += "0";
}
} }
}
if (containerName.Length > 63) if (containerName.Length > 63)
{ {
containerName = containerName.Substring(0, 63); containerName = containerName.Substring(0, 63);
} }
return containerName; return containerName;
}
} }
public virtual string NormalizeBlobName(string blobName) public virtual string NormalizeBlobName(string blobName)

51
framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs

@ -1,5 +1,7 @@
using System.Text.RegularExpressions; using System.Globalization;
using System.Text.RegularExpressions;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
namespace Volo.Abp.BlobStoring.Aws namespace Volo.Abp.BlobStoring.Aws
{ {
@ -10,35 +12,38 @@ namespace Volo.Abp.BlobStoring.Aws
/// </summary> /// </summary>
public virtual string NormalizeContainerName(string containerName) public virtual string NormalizeContainerName(string containerName)
{ {
// All letters in a container name must be lowercase. using (CultureHelper.Use(CultureInfo.InvariantCulture))
containerName = containerName.ToLowerInvariant(); {
// All letters in a container name must be lowercase.
containerName = containerName.ToLower();
// Container names can contain only letters, numbers, and the dash (-) character. // Container names can contain only letters, numbers, and the dash (-) character.
containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty);
// Every dash (-) character must be immediately preceded and followed by a letter or number; // Every dash (-) character must be immediately preceded and followed by a letter or number;
// consecutive dashes are not permitted in container names. // consecutive dashes are not permitted in container names.
// Container names must start or end with a letter or number // Container names must start or end with a letter or number
containerName = Regex.Replace(containerName, "-{2,}", "-"); containerName = Regex.Replace(containerName, "-{2,}", "-");
containerName = Regex.Replace(containerName, "^-", string.Empty); containerName = Regex.Replace(containerName, "^-", string.Empty);
containerName = Regex.Replace(containerName, "-$", string.Empty); containerName = Regex.Replace(containerName, "-$", string.Empty);
// Container names must be from 3 through 63 characters long. // Container names must be from 3 through 63 characters long.
if (containerName.Length < 3) if (containerName.Length < 3)
{
var length = containerName.Length;
for (var i = 0; i < 3 - length; i++)
{ {
containerName += "0"; var length = containerName.Length;
for (var i = 0; i < 3 - length; i++)
{
containerName += "0";
}
} }
}
if (containerName.Length > 63) if (containerName.Length > 63)
{ {
containerName = containerName.Substring(0, 63); containerName = containerName.Substring(0, 63);
} }
return containerName; return containerName;
}
} }
/// <summary> /// <summary>

51
framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs

@ -1,5 +1,7 @@
using System.Text.RegularExpressions; using System.Globalization;
using System.Text.RegularExpressions;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
namespace Volo.Abp.BlobStoring.Azure namespace Volo.Abp.BlobStoring.Azure
{ {
@ -10,35 +12,38 @@ namespace Volo.Abp.BlobStoring.Azure
/// </summary> /// </summary>
public virtual string NormalizeContainerName(string containerName) public virtual string NormalizeContainerName(string containerName)
{ {
// All letters in a container name must be lowercase. using (CultureHelper.Use(CultureInfo.InvariantCulture))
containerName = containerName.ToLowerInvariant(); {
// All letters in a container name must be lowercase.
containerName = containerName.ToLower();
// Container names can contain only letters, numbers, and the dash (-) character. // Container names can contain only letters, numbers, and the dash (-) character.
containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty);
// Every dash (-) character must be immediately preceded and followed by a letter or number; // Every dash (-) character must be immediately preceded and followed by a letter or number;
// consecutive dashes are not permitted in container names. // consecutive dashes are not permitted in container names.
// Container names must start or end with a letter or number // Container names must start or end with a letter or number
containerName = Regex.Replace(containerName, "-{2,}", "-"); containerName = Regex.Replace(containerName, "-{2,}", "-");
containerName = Regex.Replace(containerName, "^-", string.Empty); containerName = Regex.Replace(containerName, "^-", string.Empty);
containerName = Regex.Replace(containerName, "-$", string.Empty); containerName = Regex.Replace(containerName, "-$", string.Empty);
// Container names must be from 3 through 63 characters long. // Container names must be from 3 through 63 characters long.
if (containerName.Length < 3) if (containerName.Length < 3)
{
var length = containerName.Length;
for (var i = 0; i < 3 - length; i++)
{ {
containerName += "0"; var length = containerName.Length;
for (var i = 0; i < 3 - length; i++)
{
containerName += "0";
}
} }
}
if (containerName.Length > 63) if (containerName.Length > 63)
{ {
containerName = containerName.Substring(0, 63); containerName = containerName.Substring(0, 63);
} }
return containerName; return containerName;
}
} }
/// <summary> /// <summary>

19
framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobNamingNormalizer.cs

@ -1,8 +1,10 @@
using System; using System;
using System.Globalization;
using System.Runtime; using System.Runtime;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
namespace Volo.Abp.BlobStoring.FileSystem namespace Volo.Abp.BlobStoring.FileSystem
{ {
@ -27,15 +29,18 @@ namespace Volo.Abp.BlobStoring.FileSystem
protected virtual string Normalize(string fileName) protected virtual string Normalize(string fileName)
{ {
var os = _iosPlatformProvider.GetCurrentOSPlatform(); using (CultureHelper.Use(CultureInfo.InvariantCulture))
if (os == OSPlatform.Windows)
{ {
// A filename cannot contain any of the following characters: \ / : * ? " < > | var os = _iosPlatformProvider.GetCurrentOSPlatform();
// In order to support the directory included in the blob name, remove / and \ if (os == OSPlatform.Windows)
fileName = Regex.Replace(fileName, "[:\\*\\?\"<>\\|]", string.Empty); {
} // A filename cannot contain any of the following characters: \ / : * ? " < > |
// In order to support the directory included in the blob name, remove / and \
fileName = Regex.Replace(fileName, "[:\\*\\?\"<>\\|]", string.Empty);
}
return fileName; return fileName;
}
} }
} }
} }

51
framework/src/Volo.Abp.BlobStoring.Minio/Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs

@ -1,5 +1,7 @@
using System.Text.RegularExpressions; using System.Globalization;
using System.Text.RegularExpressions;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
namespace Volo.Abp.BlobStoring.Minio namespace Volo.Abp.BlobStoring.Minio
{ {
@ -10,35 +12,38 @@ namespace Volo.Abp.BlobStoring.Minio
/// </summary> /// </summary>
public virtual string NormalizeContainerName(string containerName) public virtual string NormalizeContainerName(string containerName)
{ {
// All letters in a container name must be lowercase. using (CultureHelper.Use(CultureInfo.InvariantCulture))
containerName = containerName.ToLowerInvariant(); {
// All letters in a container name must be lowercase.
containerName = containerName.ToLower();
// Container names can contain only letters, numbers, and the dash (-) character. // Container names can contain only letters, numbers, and the dash (-) character.
containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty);
// Every dash (-) character must be immediately preceded and followed by a letter or number; // Every dash (-) character must be immediately preceded and followed by a letter or number;
// consecutive dashes are not permitted in container names. // consecutive dashes are not permitted in container names.
// Container names must start or end with a letter or number // Container names must start or end with a letter or number
containerName = Regex.Replace(containerName, "-{2,}", "-"); containerName = Regex.Replace(containerName, "-{2,}", "-");
containerName = Regex.Replace(containerName, "^-", string.Empty); containerName = Regex.Replace(containerName, "^-", string.Empty);
containerName = Regex.Replace(containerName, "-$", string.Empty); containerName = Regex.Replace(containerName, "-$", string.Empty);
// Container names must be from 3 through 63 characters long. // Container names must be from 3 through 63 characters long.
if (containerName.Length < 3) if (containerName.Length < 3)
{
var length = containerName.Length;
for (var i = 0; i < 3 - length; i++)
{ {
containerName += "0"; var length = containerName.Length;
for (var i = 0; i < 3 - length; i++)
{
containerName += "0";
}
} }
}
if (containerName.Length > 63) if (containerName.Length > 63)
{ {
containerName = containerName.Substring(0, 63); containerName = containerName.Substring(0, 63);
} }
return containerName; return containerName;
}
} }
/// <summary> /// <summary>

Loading…
Cancel
Save