Skip to content

Commit 0ff2950

Browse files
authored
[Storage] Fix blob encoding in batch. (Azure#22514)
* fix blob name encoding. * cl
1 parent 8e70c2f commit 0ff2950

File tree

8 files changed

+1212
-8
lines changed

8 files changed

+1212
-8
lines changed

sdk/storage/Azure.Storage.Blobs.Batch/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
- Added support for service version 2020-10-02.
66
- TenantId can now be discovered through the service challenge response, when using a TokenCredential for authorization.
77
- A new property is now available on the ClientOptions called `EnableTenantDiscovery`. If set to true, the client will attempt an initial unauthorized request to the service to prompt a challenge containing the tenantId hint.
8-
9-
- This release contains bug fixes to improve quality.
8+
- Fixed bug where blob name was not encoded properly when using batch operations.
109

1110
## 12.6.0 (2021-06-08)
1211
- Includes all features from 12.6.0-beta.4.

sdk/storage/Azure.Storage.Blobs.Batch/src/Azure.Storage.Blobs.Batch.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<Compile Include="$(AzureStorageSharedSources)Errors.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
4040
<Compile Include="$(AzureStorageSharedSources)Errors.Clients.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
4141
<Compile Include="$(AzureStorageSharedSources)StorageClientDiagnostics.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
42+
<Compile Include="$(AzureStorageSharedSources)StorageExtensions.cs" LinkBase="Shared" />
4243
<Compile Include="$(AzureStorageSharedSources)StorageExceptionExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
4344
<Compile Include="$(AzureStorageSharedSources)StorageVersionExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
4445
</ItemGroup>

sdk/storage/Azure.Storage.Blobs.Batch/src/BlobBatch.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Azure.Storage.Blobs.Batch;
99
using Azure.Storage.Blobs.Batch.Models;
1010
using Azure.Storage.Blobs.Models;
11+
using Azure.Storage.Shared;
1112

1213
namespace Azure.Storage.Blobs.Specialized
1314
{
@@ -195,7 +196,7 @@ public virtual Response DeleteBlob(
195196

196197
HttpMessage message = BlobRestClient.CreateDeleteRequest(
197198
containerName: blobContainerName,
198-
blob: blobName,
199+
blob: blobName.EscapePath(),
199200
timeout: null,
200201
leaseId: conditions?.LeaseId,
201202
deleteSnapshots: snapshotsOption == DeleteSnapshotsOption.None ? null : (DeleteSnapshotsOptionType?)snapshotsOption,
@@ -310,7 +311,7 @@ public virtual Response SetBlobAccessTier(
310311

311312
HttpMessage message = BlobRestClient.CreateSetAccessTierRequest(
312313
containerName: blobContainerName,
313-
blob: blobName,
314+
blob: blobName.EscapePath(),
314315
accessTier.ToBatchAccessTier(),
315316
timeout: null,
316317
rehydratePriority: rehydratePriority.ToBatchRehydratePriority(),

sdk/storage/Azure.Storage.Blobs.Batch/tests/BlobBatchClientTests.cs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,28 @@ public async Task Delete_Basic()
260260
await scenario.AssertDeleted(blobs);
261261
}
262262

263+
[RecordedTest]
264+
public async Task Delete_SpecialCharacters()
265+
{
266+
await using TestScenario scenario = Scenario();
267+
BlobClient[] blobs = await scenario.CreateBlobsAsync(3, prefix: "blob ąęó");
268+
269+
BlobBatchClient client = scenario.GetBlobBatchClient();
270+
271+
using BlobBatch batch = client.CreateBatch();
272+
Response[] responses = new Response[]
273+
{
274+
batch.DeleteBlob(blobs[0].Uri),
275+
batch.DeleteBlob(blobs[1].Uri),
276+
batch.DeleteBlob(blobs[2].Uri)
277+
};
278+
Response response = await client.SubmitBatchAsync(batch);
279+
280+
scenario.AssertStatus(202, response);
281+
scenario.AssertStatus(202, responses);
282+
await scenario.AssertDeleted(blobs);
283+
}
284+
263285
[RecordedTest]
264286
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2019_12_12)]
265287
public async Task Delete_Basic_AccountSas()
@@ -585,6 +607,27 @@ public async Task SetBlobAccessTier_Basic()
585607
await scenario.AssertTiers(AccessTier.Cool, blobs);
586608
}
587609

610+
[RecordedTest]
611+
public async Task SetBlobAccessTier_SpecialCharacters()
612+
{
613+
await using TestScenario scenario = Scenario();
614+
BlobClient[] blobs = await scenario.CreateBlobsAsync(3, prefix: "blob ąęó");
615+
616+
BlobBatchClient client = scenario.GetBlobBatchClient();
617+
using BlobBatch batch = client.CreateBatch();
618+
Response[] responses = new Response[]
619+
{
620+
batch.SetBlobAccessTier(blobs[0].Uri, AccessTier.Cool),
621+
batch.SetBlobAccessTier(blobs[1].Uri, AccessTier.Cool),
622+
batch.SetBlobAccessTier(blobs[2].Uri, AccessTier.Cool)
623+
};
624+
Response response = await client.SubmitBatchAsync(batch);
625+
626+
scenario.AssertStatus(202, response);
627+
scenario.AssertStatus(200, responses);
628+
await scenario.AssertTiers(AccessTier.Cool, blobs);
629+
}
630+
588631
[Test]
589632
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2019_12_12)]
590633
[LiveOnly] // https://github.com/Azure/azure-sdk-for-net/issues/18058
@@ -1007,12 +1050,12 @@ public async Task<BlobContainerClient> CreateContainerAsync()
10071050
return test.Container;
10081051
}
10091052

1010-
public async Task<BlobClient[]> CreateBlobsAsync(BlobContainerClient container, int count)
1053+
public async Task<BlobClient[]> CreateBlobsAsync(BlobContainerClient container, int count, string prefix="blob")
10111054
{
10121055
BlobClient[] blobs = new BlobClient[count];
10131056
for (int i = 0; i < count; i++)
10141057
{
1015-
blobs[i] = _test.InstrumentClient(container.GetBlobClient("blob" + (++_blobId)));
1058+
blobs[i] = _test.InstrumentClient(container.GetBlobClient(prefix + (++_blobId)));
10161059
await blobs[i].UploadAsync(BinaryData.FromBytes(_test.GetRandomBuffer(Constants.KB)));
10171060
}
10181061
return blobs;
@@ -1029,8 +1072,8 @@ public async Task<BlockBlobClient[]> CreateBlockBlobsAsync(BlobContainerClient c
10291072
return blobs;
10301073
}
10311074

1032-
public async Task<BlobClient[]> CreateBlobsAsync(int count) =>
1033-
await CreateBlobsAsync(await CreateContainerAsync(), count);
1075+
public async Task<BlobClient[]> CreateBlobsAsync(int count, string prefix="blob") =>
1076+
await CreateBlobsAsync(await CreateContainerAsync(), count, prefix);
10341077

10351078
public async Task<BlockBlobClient[]> CreateBlockBlobsAsync(int count) =>
10361079
await CreateBlockBlobsAsync(await CreateContainerAsync(), count);

0 commit comments

Comments
 (0)