Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] Fix for truncating URL paths with "#" #44941

Merged
merged 9 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/src/BlobUriBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public BlobUriBuilder(Uri uri, bool trimBlobNameSlashes)
// Find the account, container, & blob names (if any)
if (!string.IsNullOrEmpty(uri.AbsolutePath))
{
var path = uri.GetPath();
var path = string.Concat(uri.GetPath(), uri.Fragment);

var startIndex = 0;

Expand Down
33 changes: 33 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using Azure.Storage.Test;
using Azure.Storage.Test.Shared;
using Azure.Storage.Tests.Shared;
using BenchmarkDotNet.Toolchains;
amnguye marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.Extensions.Options;
using Moq;
using Moq.Protected;
using NUnit.Framework;
Expand Down Expand Up @@ -104,6 +106,37 @@ public async Task Ctor_ConnectionStringEscapeBlobName()
Assert.AreEqual(uploadResponse.Value.ETag, propertiesResponse.Value.ETag);
}

[RecordedTest]
public async Task Ctor_EscapeBlobName()
{
// Arrange
string blobName = "!*'();[]:@&%=+$,/#äÄöÖüÜß";
await using DisposingContainer test = await GetTestContainerAsync();
var data = GetRandomBuffer(Constants.KB);
BlobClient blob = InstrumentClient(test.Container.GetBlobClient(blobName));
ETag originalEtag;
using (var stream = new MemoryStream(data))
{
BlobContentInfo info = await blob.UploadAsync(stream);
originalEtag = info.ETag;
}

// Act
BlobUriBuilder uriBuilder = new BlobUriBuilder(new Uri(Tenants.TestConfigOAuth.BlobServiceEndpoint))
{
BlobContainerName = blob.BlobContainerName,
BlobName = blobName
};
BlobBaseClient freshBlobClient = InstrumentClient(new BlobBaseClient(
uriBuilder.ToUri(),
Tenants.GetNewSharedKeyCredentials()));

// Assert
Assert.AreEqual(blobName, freshBlobClient.Name);
BlobProperties propertiesResponse = await freshBlobClient.GetPropertiesAsync();
Assert.AreEqual(originalEtag, propertiesResponse.ETag);
}

[RecordedTest]
public void Ctor_Uri()
{
Expand Down
Loading