Skip to content

Commit 2b4466a

Browse files
Copiloteerhardt
andcommitted
Fix blob container connection string format exception
Co-authored-by: eerhardt <[email protected]>
1 parent 687fa3a commit 2b4466a

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/Aspire.Hosting.Azure.Storage/AzureBlobStorageResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal ReferenceExpression GetConnectionString(string? blobContainerName)
3939
}
4040

4141
ReferenceExpressionBuilder builder = new();
42-
builder.Append($"{Endpoint}=\"{ConnectionStringExpression}\";");
42+
builder.Append($"{Endpoint}={ConnectionStringExpression};");
4343

4444
if (!string.IsNullOrEmpty(blobContainerName))
4545
{

src/Components/Aspire.Azure.Storage.Blobs/AzureBlobStorageContainerSettings.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,25 @@ void IConnectionStringSettings.ParseConnectionString(string? connectionString)
2727
const string Endpoint = nameof(Endpoint);
2828
const string ContainerName = nameof(ContainerName);
2929

30-
DbConnectionStringBuilder builder = new() { ConnectionString = connectionString };
31-
if (builder.TryGetValue(Endpoint, out var endpoint) && builder.TryGetValue(ContainerName, out var containerName))
30+
try
3231
{
33-
ConnectionString = endpoint.ToString();
34-
BlobContainerName = containerName.ToString();
32+
DbConnectionStringBuilder builder = new() { ConnectionString = connectionString };
33+
if (builder.TryGetValue(Endpoint, out var endpoint) && builder.TryGetValue(ContainerName, out var containerName))
34+
{
35+
// Remove any quotes around the endpoint value
36+
string endpointStr = endpoint?.ToString() ?? string.Empty;
37+
if (endpointStr.StartsWith("\"") && endpointStr.EndsWith("\"") && endpointStr.Length >= 2)
38+
{
39+
endpointStr = endpointStr.Substring(1, endpointStr.Length - 2);
40+
}
41+
42+
ConnectionString = endpointStr;
43+
BlobContainerName = containerName?.ToString();
44+
}
45+
}
46+
catch (ArgumentException)
47+
{
48+
throw;
3549
}
3650
}
3751
}

tests/Aspire.Azure.Storage.Blobs.Tests/AzureBlobStorageContainerSettingsTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,17 @@ public void ParseConnectionString_valid_input(string connectionString)
4949
Assert.Equal("https://example.blob.core.windows.net", settings.ConnectionString);
5050
Assert.Equal("my-container", settings.BlobContainerName);
5151
}
52+
53+
[Fact]
54+
public void ParseConnectionString_with_quoted_endpoint()
55+
{
56+
// This test reproduces the issue where the connection string has quotes around the endpoint value
57+
var settings = new AzureBlobStorageContainerSettings();
58+
string connectionString = "Endpoint=\"https://example.blob.core.windows.net\";ContainerName=my-container";
59+
60+
((IConnectionStringSettings)settings).ParseConnectionString(connectionString);
61+
62+
Assert.Equal("https://example.blob.core.windows.net", settings.ConnectionString);
63+
Assert.Equal("my-container", settings.BlobContainerName);
64+
}
5265
}

0 commit comments

Comments
 (0)