Skip to content

Commit ef4b7c5

Browse files
authored
Resolved the issue in datalake/file where file/path/directory/share/f… (#796)
* Resolved the issue in datalake/file where file/path/directory/share/filesystem name are not encoded. * Refined special char string * Resolve comments.
1 parent 95fea7a commit ef4b7c5

17 files changed

+105
-30
lines changed

sdk/storage/azure-storage-blobs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 1.0.0-beta.4
4+
5+
### Bug Fixes
6+
7+
* Unencoded Container/Blob name is now encoded.
8+
39
## 1.0.0-beta.3 (2020-10-13)
410

511
### New Features
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0-beta.3
1+
1.0.0-beta.4

sdk/storage/azure-storage-files-datalake/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 1.0.0-beta.4
4+
5+
### Bug Fixes
6+
7+
* Unencoded FileSystem/File/Path/Directory name is now encoded.
8+
39
## 1.0.0-beta.3 (2020-10-13)
410

511
### New Features

sdk/storage/azure-storage-files-datalake/src/datalake_directory_client.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
2828
{
2929
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
3030
auto directoryUri = std::move(parsedConnectionString.DataLakeServiceUri);
31-
directoryUri.AppendPath(fileSystemName);
32-
directoryUri.AppendPath(path);
31+
directoryUri.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));
32+
directoryUri.AppendPath(Storage::Details::UrlEncodePath(path));
3333

3434
if (parsedConnectionString.KeyCredential)
3535
{
@@ -132,9 +132,9 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
132132
FileClient DirectoryClient::GetFileClient(const std::string& path) const
133133
{
134134
auto builder = m_dfsUri;
135-
builder.AppendPath(path);
135+
builder.AppendPath(Storage::Details::UrlEncodePath(path));
136136
auto blobClient = m_blobClient;
137-
blobClient.m_blobUrl.AppendPath(path);
137+
blobClient.m_blobUrl.AppendPath(Storage::Details::UrlEncodePath(path));
138138
auto blockBlobClient = blobClient.GetBlockBlobClient();
139139
return FileClient(
140140
std::move(builder), std::move(blobClient), std::move(blockBlobClient), m_pipeline);
@@ -143,9 +143,9 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
143143
DirectoryClient DirectoryClient::GetSubDirectoryClient(const std::string& path) const
144144
{
145145
auto builder = m_dfsUri;
146-
builder.AppendPath(path);
146+
builder.AppendPath(Storage::Details::UrlEncodePath(path));
147147
auto blobClient = m_blobClient;
148-
blobClient.m_blobUrl.AppendPath(path);
148+
blobClient.m_blobUrl.AppendPath(Storage::Details::UrlEncodePath(path));
149149
return DirectoryClient(std::move(builder), std::move(blobClient), m_pipeline);
150150
}
151151

sdk/storage/azure-storage-files-datalake/src/datalake_file_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
106106
{
107107
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
108108
auto fileUri = std::move(parsedConnectionString.DataLakeServiceUri);
109-
fileUri.AppendPath(fileSystemName);
110-
fileUri.AppendPath(filePath);
109+
fileUri.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));
110+
fileUri.AppendPath(Storage::Details::UrlEncodePath(filePath));
111111

112112
if (parsedConnectionString.KeyCredential)
113113
{

sdk/storage/azure-storage-files-datalake/src/datalake_file_system_client.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
4646
{
4747
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
4848
auto fileSystemUri = std::move(parsedConnectionString.DataLakeServiceUri);
49-
fileSystemUri.AppendPath(fileSystemName);
49+
fileSystemUri.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));
5050

5151
if (parsedConnectionString.KeyCredential)
5252
{
@@ -163,15 +163,15 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
163163
PathClient FileSystemClient::GetPathClient(const std::string& path) const
164164
{
165165
auto builder = m_dfsUri;
166-
builder.AppendPath(path);
166+
builder.AppendPath(Storage::Details::UrlEncodePath(path));
167167
return PathClient(builder, m_blobContainerClient.GetBlobClient(path), m_pipeline);
168168
}
169169

170170
FileClient FileSystemClient::GetFileClient(const std::string& path) const
171171
{
172172

173173
auto builder = m_dfsUri;
174-
builder.AppendPath(path);
174+
builder.AppendPath(Storage::Details::UrlEncodePath(path));
175175
auto blobClient = m_blobContainerClient.GetBlobClient(path);
176176
auto blockBlobClient = blobClient.GetBlockBlobClient();
177177
return FileClient(
@@ -181,7 +181,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
181181
DirectoryClient FileSystemClient::GetDirectoryClient(const std::string& path) const
182182
{
183183
auto builder = m_dfsUri;
184-
builder.AppendPath(path);
184+
builder.AppendPath(Storage::Details::UrlEncodePath(path));
185185
return DirectoryClient(builder, m_blobContainerClient.GetBlobClient(path), m_pipeline);
186186
}
187187

sdk/storage/azure-storage-files-datalake/src/datalake_path_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
9090
{
9191
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
9292
auto pathUri = std::move(parsedConnectionString.DataLakeServiceUri);
93-
pathUri.AppendPath(fileSystemName);
94-
pathUri.AppendPath(path);
93+
pathUri.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));
94+
pathUri.AppendPath(Storage::Details::UrlEncodePath(path));
9595

9696
if (parsedConnectionString.KeyCredential)
9797
{

sdk/storage/azure-storage-files-datalake/src/datalake_service_client.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
164164
FileSystemClient ServiceClient::GetFileSystemClient(const std::string& fileSystemName) const
165165
{
166166
auto builder = m_dfsUri;
167-
builder.AppendPath(fileSystemName);
167+
builder.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));
168168
return FileSystemClient(
169169
builder, m_blobServiceClient.GetBlobContainerClient(fileSystemName), m_pipeline);
170170
}
@@ -179,8 +179,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
179179
blobOptions.MaxResults = options.MaxResults;
180180
auto result = m_blobServiceClient.ListBlobContainersSegment(blobOptions);
181181
auto response = ListFileSystemsSegmentResult();
182-
response.ContinuationToken
183-
= result->ContinuationToken.empty() ? response.ContinuationToken : result->ContinuationToken;
182+
response.ContinuationToken = result->ContinuationToken.empty() ? response.ContinuationToken
183+
: result->ContinuationToken;
184184
response.Filesystems = FileSystemsFromContainerItems(result->Items);
185185
return Azure::Core::Response<ListFileSystemsSegmentResult>(
186186
std::move(response), result.ExtractRawResponse());

sdk/storage/azure-storage-files-datalake/test/datalake_file_system_client_test.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: MIT
33

44
#include "datalake_file_system_client_test.hpp"
5+
#include "azure/storage/common/crypt.hpp"
56
#include "azure/storage/files/datalake/datalake_options.hpp"
67

78
#include <algorithm>
@@ -249,4 +250,36 @@ namespace Azure { namespace Storage { namespace Test {
249250
EXPECT_LE(2U, response->Paths.size());
250251
}
251252
}
253+
254+
TEST_F(DataLakeFileSystemClientTest, UnencodedPathDirectoryFileNameWorks)
255+
{
256+
const std::string non_ascii_word = "\xE6\xB5\x8B\xE8\xAF\x95";
257+
const std::string encoded_non_ascii_word = "%E6%B5%8B%E8%AF%95";
258+
std::string baseName = "a b c / !@#$%^&*(?/<>,.;:'\"[]{}|`~\\) def" + non_ascii_word;
259+
{
260+
std::string pathName = baseName + RandomString();
261+
auto pathClient = m_fileSystemClient->GetPathClient(pathName);
262+
EXPECT_NO_THROW(pathClient.Create(Files::DataLake::PathResourceType::File));
263+
auto pathUrl = pathClient.GetUri();
264+
EXPECT_EQ(
265+
pathUrl, m_fileSystemClient->GetUri() + "/" + Storage::Details::UrlEncodePath(pathName));
266+
}
267+
{
268+
std::string directoryName = baseName + RandomString();
269+
auto directoryClient = m_fileSystemClient->GetDirectoryClient(directoryName);
270+
EXPECT_NO_THROW(directoryClient.Create());
271+
auto directoryUrl = directoryClient.GetUri();
272+
EXPECT_EQ(
273+
directoryUrl,
274+
m_fileSystemClient->GetUri() + "/" + Storage::Details::UrlEncodePath(directoryName));
275+
}
276+
{
277+
std::string fileName = baseName + RandomString();
278+
auto fileClient = m_fileSystemClient->GetFileClient(fileName);
279+
EXPECT_NO_THROW(fileClient.Create());
280+
auto fileUrl = fileClient.GetUri();
281+
EXPECT_EQ(
282+
fileUrl, m_fileSystemClient->GetUri() + "/" + Storage::Details::UrlEncodePath(fileName));
283+
}
284+
}
252285
}}} // namespace Azure::Storage::Test
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0-beta.3
1+
1.0.0-beta.4

0 commit comments

Comments
 (0)