Cannot use non-ASCII chars in metadata
vanillajonathan opened this issue · comments
Which service does this issue concern?
Blob.
Which version of the SDK was used?
11.1.3
Which platform are you using?
.NET Core 3.1
What problem was encountered?
Exception when writing metadata with non-ASCII characters.
Microsoft.Azure.Storage.StorageException: 'Request headers must contain only ASCII characters.'
Inner Exception
HttpRequestException: Request headers must contain only ASCII characters.
This exception was originally thrown at this call stack:
System.Net.Http.HttpConnection.WriteStringAsync(string)
System.Net.Http.HttpConnection.WriteHeadersAsync(System.Net.Http.Headers.HttpHeaders, string)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
System.Net.Http.HttpConnection.SendAsyncCore(System.Net.Http.HttpRequestMessage, System.Threading.CancellationToken)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
...
[Call Stack Truncated]
How can we reproduce the problem in the simplest way?
Write a non-ASCII character (such as "ñ") as blob metadata.
using System;
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Auth;
using Microsoft.Azure.Storage.Blob;
namespace BlobExperiment
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
const string accountName = "<account-name>";
const string accountKey = "<account-key>";
var storageCredentials = new StorageCredentials(accountName, accountKey);
var storageAccount = new CloudStorageAccount(storageCredentials, true);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("test");
var blockBlob = container.GetBlockBlobReference("test.jpg");
blockBlob.Metadata["Test"] = "ñ"; // The notorious ñ!
blockBlob.SetMetadata();
}
}
}
Have you found a mitigation/solution?
No.
Please see the asnwer in Azure/azure-sdk-for-net#10629 .