Skip to content

Commit

Permalink
[storage]Fixed an issue of escaping slashes in blob name unnecessaril…
Browse files Browse the repository at this point in the history
…y. (Azure#23461)

* [storage]Fixed an issue of escaping slashes in blob name unnecessarily.

* Add two more test cases.
  • Loading branch information
EmmaZhu committed Oct 13, 2022
1 parent acb2465 commit ef9938a
Show file tree
Hide file tree
Showing 22 changed files with 1,701 additions and 679 deletions.
2 changes: 2 additions & 0 deletions sdk/storage/storage-blob/CHANGELOG.md
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed an issue of escaping slashes in blob name unnecessarily.

### Other Changes

## 12.12.0-beta.1 (2022-08-26)
Expand Down
23 changes: 5 additions & 18 deletions sdk/storage/storage-blob/src/ContainerClient.ts
Expand Up @@ -55,6 +55,7 @@ import {
BlobNameToString,
ConvertInternalResponseOfListBlobFlat,
ConvertInternalResponseOfListBlobHierarchy,
EscapePath,
extractConnectionStringParts,
isIpEndpointStyle,
parseObjectReplicationRecord,
Expand Down Expand Up @@ -893,7 +894,7 @@ export class ContainerClient extends StorageClient {
* @returns A new BlobClient object for the given blob name.
*/
public getBlobClient(blobName: string): BlobClient {
return new BlobClient(appendToURLPath(this.url, this.escapePath(blobName)), this.pipeline);
return new BlobClient(appendToURLPath(this.url, EscapePath(blobName)), this.pipeline);
}

/**
Expand All @@ -902,10 +903,7 @@ export class ContainerClient extends StorageClient {
* @param blobName - An append blob name
*/
public getAppendBlobClient(blobName: string): AppendBlobClient {
return new AppendBlobClient(
appendToURLPath(this.url, this.escapePath(blobName)),
this.pipeline
);
return new AppendBlobClient(appendToURLPath(this.url, EscapePath(blobName)), this.pipeline);
}

/**
Expand All @@ -924,7 +922,7 @@ export class ContainerClient extends StorageClient {
* ```
*/
public getBlockBlobClient(blobName: string): BlockBlobClient {
return new BlockBlobClient(appendToURLPath(this.url, this.escapePath(blobName)), this.pipeline);
return new BlockBlobClient(appendToURLPath(this.url, EscapePath(blobName)), this.pipeline);
}

/**
Expand All @@ -933,18 +931,7 @@ export class ContainerClient extends StorageClient {
* @param blobName - A page blob name
*/
public getPageBlobClient(blobName: string): PageBlobClient {
return new PageBlobClient(appendToURLPath(this.url, this.escapePath(blobName)), this.pipeline);
}

/**
* Escape the blobName but keep path separator ('/'). Exactly like in the dotnet SDK client.
*/
private escapePath(blobName: string): string {
const split = blobName.split("/");
for (let i = 0; i < split.length; i++) {
split[i] = encodeURIComponent(split[i]);
}
return split.join("/");
return new PageBlobClient(appendToURLPath(this.url, EscapePath(blobName)), this.pipeline);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions sdk/storage/storage-blob/src/utils/utils.common.ts
Expand Up @@ -1250,3 +1250,14 @@ export function* ExtractPageRangeInfoItems(
};
}
}

/**
* Escape the blobName but keep path separator ('/').
*/
export function EscapePath(blobName: string): string {
const split = blobName.split("/");
for (let i = 0; i < split.length; i++) {
split[i] = encodeURIComponent(split[i]);
}
return split.join("/");
}
2 changes: 2 additions & 0 deletions sdk/storage/storage-file-datalake/CHANGELOG.md
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed an issue of escaping slashes in file or directory path unnecessarily.

### Other Changes

## 12.11.0-beta.1 (2022-08-26)
Expand Down

0 comments on commit ef9938a

Please sign in to comment.