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]Fixed an issue of escaping slashes in blob name unnecessarily. #23461

Merged
merged 2 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions sdk/storage/storage-blob/CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading