Skip to content

Commit ef9938a

Browse files
authored
[storage]Fixed an issue of escaping slashes in blob name unnecessarily. (Azure#23461)
* [storage]Fixed an issue of escaping slashes in blob name unnecessarily. * Add two more test cases.
1 parent acb2465 commit ef9938a

22 files changed

+1701
-679
lines changed

sdk/storage/storage-blob/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
- Fixed an issue of escaping slashes in blob name unnecessarily.
12+
1113
### Other Changes
1214

1315
## 12.12.0-beta.1 (2022-08-26)

sdk/storage/storage-blob/src/ContainerClient.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
BlobNameToString,
5656
ConvertInternalResponseOfListBlobFlat,
5757
ConvertInternalResponseOfListBlobHierarchy,
58+
EscapePath,
5859
extractConnectionStringParts,
5960
isIpEndpointStyle,
6061
parseObjectReplicationRecord,
@@ -893,7 +894,7 @@ export class ContainerClient extends StorageClient {
893894
* @returns A new BlobClient object for the given blob name.
894895
*/
895896
public getBlobClient(blobName: string): BlobClient {
896-
return new BlobClient(appendToURLPath(this.url, this.escapePath(blobName)), this.pipeline);
897+
return new BlobClient(appendToURLPath(this.url, EscapePath(blobName)), this.pipeline);
897898
}
898899

899900
/**
@@ -902,10 +903,7 @@ export class ContainerClient extends StorageClient {
902903
* @param blobName - An append blob name
903904
*/
904905
public getAppendBlobClient(blobName: string): AppendBlobClient {
905-
return new AppendBlobClient(
906-
appendToURLPath(this.url, this.escapePath(blobName)),
907-
this.pipeline
908-
);
906+
return new AppendBlobClient(appendToURLPath(this.url, EscapePath(blobName)), this.pipeline);
909907
}
910908

911909
/**
@@ -924,7 +922,7 @@ export class ContainerClient extends StorageClient {
924922
* ```
925923
*/
926924
public getBlockBlobClient(blobName: string): BlockBlobClient {
927-
return new BlockBlobClient(appendToURLPath(this.url, this.escapePath(blobName)), this.pipeline);
925+
return new BlockBlobClient(appendToURLPath(this.url, EscapePath(blobName)), this.pipeline);
928926
}
929927

930928
/**
@@ -933,18 +931,7 @@ export class ContainerClient extends StorageClient {
933931
* @param blobName - A page blob name
934932
*/
935933
public getPageBlobClient(blobName: string): PageBlobClient {
936-
return new PageBlobClient(appendToURLPath(this.url, this.escapePath(blobName)), this.pipeline);
937-
}
938-
939-
/**
940-
* Escape the blobName but keep path separator ('/'). Exactly like in the dotnet SDK client.
941-
*/
942-
private escapePath(blobName: string): string {
943-
const split = blobName.split("/");
944-
for (let i = 0; i < split.length; i++) {
945-
split[i] = encodeURIComponent(split[i]);
946-
}
947-
return split.join("/");
934+
return new PageBlobClient(appendToURLPath(this.url, EscapePath(blobName)), this.pipeline);
948935
}
949936

950937
/**

sdk/storage/storage-blob/src/utils/utils.common.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,3 +1250,14 @@ export function* ExtractPageRangeInfoItems(
12501250
};
12511251
}
12521252
}
1253+
1254+
/**
1255+
* Escape the blobName but keep path separator ('/').
1256+
*/
1257+
export function EscapePath(blobName: string): string {
1258+
const split = blobName.split("/");
1259+
for (let i = 0; i < split.length; i++) {
1260+
split[i] = encodeURIComponent(split[i]);
1261+
}
1262+
return split.join("/");
1263+
}

sdk/storage/storage-file-datalake/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
- Fixed an issue of escaping slashes in file or directory path unnecessarily.
12+
1113
### Other Changes
1214

1315
## 12.11.0-beta.1 (2022-08-26)

0 commit comments

Comments
 (0)