From 62f2da1ee61dc46fca83068399c018000884b01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20=C3=87A=C4=9EDA=C5=9E?= Date: Wed, 16 Sep 2020 10:33:26 +0300 Subject: [PATCH 1/2] use ToLowerInvariant when normalizing container name --- .../Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs | 5 +++-- .../Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs | 2 +- .../Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs | 2 +- .../Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs b/framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs index b456d7abb6..8790a5b7ee 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs +++ b/framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using System.Globalization; +using System.Text.RegularExpressions; using Volo.Abp.DependencyInjection; namespace Volo.Abp.BlobStoring.Aliyun @@ -13,7 +14,7 @@ namespace Volo.Abp.BlobStoring.Aliyun public virtual string NormalizeContainerName(string containerName) { // All letters in a container name must be lowercase. - containerName = containerName.ToLower(); + containerName = containerName.ToLowerInvariant(); // Container names can contain only letters, numbers, and the dash (-) character. containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs index cd8eca021e..9f1ee0968e 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs +++ b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs @@ -11,7 +11,7 @@ namespace Volo.Abp.BlobStoring.Aws public virtual string NormalizeContainerName(string containerName) { // All letters in a container name must be lowercase. - containerName = containerName.ToLower(); + containerName = containerName.ToLowerInvariant(); // Container names can contain only letters, numbers, and the dash (-) character. containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); diff --git a/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs b/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs index 43b479e08e..fab0c9f362 100644 --- a/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs +++ b/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs @@ -11,7 +11,7 @@ namespace Volo.Abp.BlobStoring.Azure public virtual string NormalizeContainerName(string containerName) { // All letters in a container name must be lowercase. - containerName = containerName.ToLower(); + containerName = containerName.ToLowerInvariant(); // Container names can contain only letters, numbers, and the dash (-) character. containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); diff --git a/framework/src/Volo.Abp.BlobStoring.Minio/Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs b/framework/src/Volo.Abp.BlobStoring.Minio/Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs index d350910105..68292520d4 100644 --- a/framework/src/Volo.Abp.BlobStoring.Minio/Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs +++ b/framework/src/Volo.Abp.BlobStoring.Minio/Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs @@ -11,7 +11,7 @@ namespace Volo.Abp.BlobStoring.Minio public virtual string NormalizeContainerName(string containerName) { // All letters in a container name must be lowercase. - containerName = containerName.ToLower(); + containerName = containerName.ToLowerInvariant(); // Container names can contain only letters, numbers, and the dash (-) character. containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); From bc5da1f7225506d47330b613b2978f38ef793bca Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Wed, 16 Sep 2020 15:50:46 +0800 Subject: [PATCH 2/2] Use InvariantCulture for ToLower and Regex. --- .../Aliyun/AliyunBlobNamingNormalizer.cs | 52 ++++++++++--------- .../Aws/AwsBlobNamingNormalizer.cs | 51 ++++++++++-------- .../Azure/AzureBlobNamingNormalizer.cs | 51 ++++++++++-------- .../FileSystemBlobNamingNormalizer.cs | 19 ++++--- .../Minio/MinioBlobNamingNormalizer.cs | 51 ++++++++++-------- 5 files changed, 124 insertions(+), 100 deletions(-) diff --git a/framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs b/framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs index 8790a5b7ee..cf8ff42973 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs +++ b/framework/src/Volo.Abp.BlobStoring.Aliyun/Volo/Abp/BlobStoring/Aliyun/AliyunBlobNamingNormalizer.cs @@ -1,47 +1,51 @@ using System.Globalization; using System.Text.RegularExpressions; using Volo.Abp.DependencyInjection; +using Volo.Abp.Localization; namespace Volo.Abp.BlobStoring.Aliyun { public class AliyunBlobNamingNormalizer : IBlobNamingNormalizer, ITransientDependency { /// - /// Container names can contain only letters, numbers, and the dash (-) character - /// they can't start or end with the dash (-) character + /// Container names can contain only letters, numbers, and the dash (-) character + /// they can't start or end with the dash (-) character /// Container names must be from 3 through 63 characters long /// public virtual string NormalizeContainerName(string containerName) { - // All letters in a container name must be lowercase. - containerName = containerName.ToLowerInvariant(); + using (CultureHelper.Use(CultureInfo.InvariantCulture)) + { + // All letters in a container name must be lowercase. + containerName = containerName.ToLower(); - // Container names can contain only letters, numbers, and the dash (-) character. - containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); + // Container names can contain only letters, numbers, and the dash (-) character. + containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); - // Every dash (-) character must be immediately preceded and followed by a letter or number; - // consecutive dashes are not permitted in container names. - // Container names must start or end with a letter or number - containerName = Regex.Replace(containerName, "-{2,}", "-"); - containerName = Regex.Replace(containerName, "^-", string.Empty); - containerName = Regex.Replace(containerName, "-$", string.Empty); + // Every dash (-) character must be immediately preceded and followed by a letter or number; + // consecutive dashes are not permitted in container names. + // Container names must start or end with a letter or number + containerName = Regex.Replace(containerName, "-{2,}", "-"); + containerName = Regex.Replace(containerName, "^-", string.Empty); + containerName = Regex.Replace(containerName, "-$", string.Empty); - // Container names must be from 3 through 63 characters long. - if (containerName.Length < 3) - { - var length = containerName.Length; - for (var i = 0; i < 3 - length; i++) + // Container names must be from 3 through 63 characters long. + if (containerName.Length < 3) { - containerName += "0"; + var length = containerName.Length; + for (var i = 0; i < 3 - length; i++) + { + containerName += "0"; + } } - } - if (containerName.Length > 63) - { - containerName = containerName.Substring(0, 63); - } + if (containerName.Length > 63) + { + containerName = containerName.Substring(0, 63); + } - return containerName; + return containerName; + } } public virtual string NormalizeBlobName(string blobName) diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs index 9f1ee0968e..3779f9ff70 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs +++ b/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.Localization; namespace Volo.Abp.BlobStoring.Aws { @@ -10,35 +12,38 @@ namespace Volo.Abp.BlobStoring.Aws /// public virtual string NormalizeContainerName(string containerName) { - // All letters in a container name must be lowercase. - containerName = containerName.ToLowerInvariant(); + using (CultureHelper.Use(CultureInfo.InvariantCulture)) + { + // All letters in a container name must be lowercase. + containerName = containerName.ToLower(); - // Container names can contain only letters, numbers, and the dash (-) character. - containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); + // Container names can contain only letters, numbers, and the dash (-) character. + containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); - // Every dash (-) character must be immediately preceded and followed by a letter or number; - // consecutive dashes are not permitted in container names. - // Container names must start or end with a letter or number - containerName = Regex.Replace(containerName, "-{2,}", "-"); - containerName = Regex.Replace(containerName, "^-", string.Empty); - containerName = Regex.Replace(containerName, "-$", string.Empty); + // Every dash (-) character must be immediately preceded and followed by a letter or number; + // consecutive dashes are not permitted in container names. + // Container names must start or end with a letter or number + containerName = Regex.Replace(containerName, "-{2,}", "-"); + containerName = Regex.Replace(containerName, "^-", string.Empty); + containerName = Regex.Replace(containerName, "-$", string.Empty); - // Container names must be from 3 through 63 characters long. - if (containerName.Length < 3) - { - var length = containerName.Length; - for (var i = 0; i < 3 - length; i++) + // Container names must be from 3 through 63 characters long. + if (containerName.Length < 3) { - containerName += "0"; + var length = containerName.Length; + for (var i = 0; i < 3 - length; i++) + { + containerName += "0"; + } } - } - if (containerName.Length > 63) - { - containerName = containerName.Substring(0, 63); - } + if (containerName.Length > 63) + { + containerName = containerName.Substring(0, 63); + } - return containerName; + return containerName; + } } /// diff --git a/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs b/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs index fab0c9f362..767a7b6fea 100644 --- a/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobNamingNormalizer.cs +++ b/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.Localization; namespace Volo.Abp.BlobStoring.Azure { @@ -10,35 +12,38 @@ namespace Volo.Abp.BlobStoring.Azure /// public virtual string NormalizeContainerName(string containerName) { - // All letters in a container name must be lowercase. - containerName = containerName.ToLowerInvariant(); + using (CultureHelper.Use(CultureInfo.InvariantCulture)) + { + // All letters in a container name must be lowercase. + containerName = containerName.ToLower(); - // Container names can contain only letters, numbers, and the dash (-) character. - containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); + // Container names can contain only letters, numbers, and the dash (-) character. + containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); - // Every dash (-) character must be immediately preceded and followed by a letter or number; - // consecutive dashes are not permitted in container names. - // Container names must start or end with a letter or number - containerName = Regex.Replace(containerName, "-{2,}", "-"); - containerName = Regex.Replace(containerName, "^-", string.Empty); - containerName = Regex.Replace(containerName, "-$", string.Empty); + // Every dash (-) character must be immediately preceded and followed by a letter or number; + // consecutive dashes are not permitted in container names. + // Container names must start or end with a letter or number + containerName = Regex.Replace(containerName, "-{2,}", "-"); + containerName = Regex.Replace(containerName, "^-", string.Empty); + containerName = Regex.Replace(containerName, "-$", string.Empty); - // Container names must be from 3 through 63 characters long. - if (containerName.Length < 3) - { - var length = containerName.Length; - for (var i = 0; i < 3 - length; i++) + // Container names must be from 3 through 63 characters long. + if (containerName.Length < 3) { - containerName += "0"; + var length = containerName.Length; + for (var i = 0; i < 3 - length; i++) + { + containerName += "0"; + } } - } - if (containerName.Length > 63) - { - containerName = containerName.Substring(0, 63); - } + if (containerName.Length > 63) + { + containerName = containerName.Substring(0, 63); + } - return containerName; + return containerName; + } } /// diff --git a/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobNamingNormalizer.cs b/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobNamingNormalizer.cs index f7d273dca7..94c19b07f8 100644 --- a/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobNamingNormalizer.cs +++ b/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobNamingNormalizer.cs @@ -1,8 +1,10 @@ using System; +using System.Globalization; using System.Runtime; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using Volo.Abp.DependencyInjection; +using Volo.Abp.Localization; namespace Volo.Abp.BlobStoring.FileSystem { @@ -27,15 +29,18 @@ namespace Volo.Abp.BlobStoring.FileSystem protected virtual string Normalize(string fileName) { - var os = _iosPlatformProvider.GetCurrentOSPlatform(); - if (os == OSPlatform.Windows) + using (CultureHelper.Use(CultureInfo.InvariantCulture)) { - // 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); - } + var os = _iosPlatformProvider.GetCurrentOSPlatform(); + if (os == OSPlatform.Windows) + { + // 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; + } } } } diff --git a/framework/src/Volo.Abp.BlobStoring.Minio/Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs b/framework/src/Volo.Abp.BlobStoring.Minio/Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs index 68292520d4..c4df24f91a 100644 --- a/framework/src/Volo.Abp.BlobStoring.Minio/Volo/Abp/BlobStoring/Minio/MinioBlobNamingNormalizer.cs +++ b/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.Localization; namespace Volo.Abp.BlobStoring.Minio { @@ -10,35 +12,38 @@ namespace Volo.Abp.BlobStoring.Minio /// public virtual string NormalizeContainerName(string containerName) { - // All letters in a container name must be lowercase. - containerName = containerName.ToLowerInvariant(); + using (CultureHelper.Use(CultureInfo.InvariantCulture)) + { + // All letters in a container name must be lowercase. + containerName = containerName.ToLower(); - // Container names can contain only letters, numbers, and the dash (-) character. - containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); + // Container names can contain only letters, numbers, and the dash (-) character. + containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty); - // Every dash (-) character must be immediately preceded and followed by a letter or number; - // consecutive dashes are not permitted in container names. - // Container names must start or end with a letter or number - containerName = Regex.Replace(containerName, "-{2,}", "-"); - containerName = Regex.Replace(containerName, "^-", string.Empty); - containerName = Regex.Replace(containerName, "-$", string.Empty); + // Every dash (-) character must be immediately preceded and followed by a letter or number; + // consecutive dashes are not permitted in container names. + // Container names must start or end with a letter or number + containerName = Regex.Replace(containerName, "-{2,}", "-"); + containerName = Regex.Replace(containerName, "^-", string.Empty); + containerName = Regex.Replace(containerName, "-$", string.Empty); - // Container names must be from 3 through 63 characters long. - if (containerName.Length < 3) - { - var length = containerName.Length; - for (var i = 0; i < 3 - length; i++) + // Container names must be from 3 through 63 characters long. + if (containerName.Length < 3) { - containerName += "0"; + var length = containerName.Length; + for (var i = 0; i < 3 - length; i++) + { + containerName += "0"; + } } - } - if (containerName.Length > 63) - { - containerName = containerName.Substring(0, 63); - } + if (containerName.Length > 63) + { + containerName = containerName.Substring(0, 63); + } - return containerName; + return containerName; + } } ///