Skip to content

Commit 31e581c

Browse files
authored
[Storage] Fix issue of getting a single blob with leading slashes (#21754)
* fix slash issue for getting a single blob * remove breaking change warning
1 parent f0f8dd5 commit 31e581c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed issue of getting a single blob with leading slashes
22+
- `Get-AzStorageBlob`
2123
* Supported setting CORS rules in management plane cmdlets
2224
- `Update-AzStorageBlobServiceProperty`
2325
- `Update-AzStorageFileServiceProperty`

src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public class GetAzureStorageBlobCommand : StorageCloudBlobCmdletBase
5757
/// </summary>
5858
private const string SingleBlobVersionIDParameterSet = "SingleBlobVersionID";
5959

60-
[CmdletParameterBreakingChange("Blob", ChangeDescription = "Leading and trailing slashes will not be trimmed in a future release.")]
6160
[Parameter(Position = 0, HelpMessage = "Blob name", ParameterSetName = NameParameterSet)]
6261
[Parameter(Position = 0, Mandatory = true, HelpMessage = "Blob name", ParameterSetName = SingleBlobSnapshotTimeParameterSet)]
6362
[Parameter(Position = 0, Mandatory = true, HelpMessage = "Blob name", ParameterSetName = SingleBlobVersionIDParameterSet)]
@@ -235,7 +234,7 @@ internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localCha
235234
BlobBaseClient blobClient = null;
236235
if (UseTrack2Sdk()) // User Track2 SDK
237236
{
238-
blobClient = Util.GetTrack2BlobClient(track2container, blobName, localChannel.StorageContext, this.VersionId, false, this.SnapshotTime is null ? null : this.SnapshotTime.Value.ToUniversalTime().ToString("o").Replace("+00:00", "Z"), ClientOptions);
237+
blobClient = Util.GetTrack2BlobClient(track2container, blobName, localChannel.StorageContext, this.VersionId, false, this.SnapshotTime is null ? null : this.SnapshotTime.Value.ToUniversalTime().ToString("o").Replace("+00:00", "Z"), ClientOptions, shouldTrimSlash: false);
239238
global::Azure.Storage.Blobs.Models.BlobProperties blobProperties;
240239
try
241240
{
@@ -245,7 +244,7 @@ internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localCha
245244
{
246245
throw new ResourceNotFoundException(String.Format(Resources.BlobNotFound, blobName, containerName));
247246
}
248-
blobClient = Util.GetTrack2BlobClient(track2container, blobName, localChannel.StorageContext, this.VersionId, blobProperties.IsLatestVersion, this.SnapshotTime is null ? null : this.SnapshotTime.Value.ToUniversalTime().ToString("o").Replace("+00:00", "Z"), ClientOptions, blobProperties.BlobType);
247+
blobClient = Util.GetTrack2BlobClient(track2container, blobName, localChannel.StorageContext, this.VersionId, blobProperties.IsLatestVersion, this.SnapshotTime is null ? null : this.SnapshotTime.Value.ToUniversalTime().ToString("o").Replace("+00:00", "Z"), ClientOptions, blobProperties.BlobType, shouldTrimSlash: false);
249248

250249
AzureStorageBlob outputBlob = new AzureStorageBlob(blobClient, localChannel.StorageContext, blobProperties, ClientOptions);
251250
if (this.IncludeTag.IsPresent)

src/Storage/Storage/Common/Util.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ public static BlobBaseClient GetTrack2BlobClient(BlobContainerClient track2conta
415415
{
416416
blobUriBuilder.Snapshot = snapshot;
417417
}
418+
if (shouldTrimSlash == false)
419+
{
420+
if (options == null)
421+
{
422+
options = new BlobClientOptions();
423+
}
424+
options.TrimBlobNameSlashes = shouldTrimSlash;
425+
}
418426

419427
return GetTrack2BlobClient(blobUriBuilder.ToUri(), context, options, blobType);
420428
}

0 commit comments

Comments
 (0)