Skip to content

Commit 69a2eee

Browse files
CreateContainer gives error when passed in string isn't lower case #54
1 parent db4b093 commit 69a2eee

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// </summary>
99
// --------------------------------------------------------------------------------------------------------------------
1010

11+
using System.Text.RegularExpressions;
12+
1113
namespace Our.Umbraco.FileSystemProviders.Azure
1214
{
1315
using System;
@@ -547,7 +549,17 @@ public Stream OpenFile(string path)
547549
/// <returns>The <see cref="CloudBlobContainer"/></returns>
548550
private static CloudBlobContainer CreateContainer(CloudBlobClient cloudBlobClient, string containerName, BlobContainerPublicAccessType accessType)
549551
{
550-
CloudBlobContainer container = cloudBlobClient.GetContainerReference(containerName);
552+
containerName = containerName.ToLowerInvariant();
553+
554+
// Validate container name - from: http://stackoverflow.com/a/23364534/5018
555+
var regEx = new Regex("^[a-z0-9](?:[a-z0-9]|(\\-(?!\\-))){1,61}[a-z0-9]$|^\\$root$");
556+
var isContainerNameValid = regEx.IsMatch(containerName);
557+
if (isContainerNameValid == false)
558+
{
559+
throw new ArgumentException(string.Format("The container name {0} is not valid, see https://msdn.microsoft.com/en-us/library/azure/dd135715.aspx for the restrtictions for container names.", containerName));
560+
}
561+
562+
CloudBlobContainer container = cloudBlobClient.GetContainerReference(containerName.ToLowerInvariant());
551563
container.CreateIfNotExists();
552564
container.SetPermissions(new BlobContainerPermissions { PublicAccess = accessType });
553565
return container;

0 commit comments

Comments
 (0)