I am implementing an API to store files in Azure Blob Storage.
I am using the Microsoft library to validate the container and blob name.
NameValidator.ValidateContainerName(containerName);
NameValidator.ValidateBlobName(blobFullName);
However, it is returning some names as valid even though, by their own docs I know they are not and when I try to save them, blob storage is returning a 400 bad request, as expected. So aside from the question as to why the MS validation libraries are incomplete, how can I perform the rest of the validation in C#? Specifically, I am now failing on the part
"some ASCII or Unicode characters, like control characters (0x00 to 0x1F, \u0081, etc.)"
I have a file with \u0081 in the filename. What are the remaining invalid characters. They point us to ietf docs, but then say "some" of those characters are not allowed? Which ones? Just all control characters?
Just for clarity, here's the part that returns the 400
CloudBlockBlob blob = documentContainer.GetBlockBlobReference(blobFullName);
await blob.UploadFromStreamAsync(fileStream, token).ConfigureAwait(false);
Thanks for your help!
Update: I've added this bit of logic to check for control characters at least. If I can get something somewhat robust, I will issue a PR against Microsoft's validation code
if (blobFullName.ToCharArray().Any(c => Char.IsControl(c))) {
throw new HissyFitException(); // or do other stuff to fail validation
}