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

Resolved the issue in datalake/file where file/path/directory/share/f… #796

Merged
merged 3 commits into from
Oct 16, 2020
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
6 changes: 6 additions & 0 deletions sdk/storage/azure-storage-blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.0.0-beta.4

### Bug Fixes

* Unencoded Container/Blob name is now encoded.

## 1.0.0-beta.3 (2020-10-13)

### New Features
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blobs/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-beta.3
1.0.0-beta.4
6 changes: 6 additions & 0 deletions sdk/storage/azure-storage-files-datalake/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.0.0-beta.4

### Bug Fixes

* Unencoded FileSystem/File/Path/Directory name is now encoded.

## 1.0.0-beta.3 (2020-10-13)

### New Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto directoryUri = std::move(parsedConnectionString.DataLakeServiceUri);
directoryUri.AppendPath(fileSystemName);
directoryUri.AppendPath(path);
directoryUri.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));
directoryUri.AppendPath(Storage::Details::UrlEncodePath(path));

if (parsedConnectionString.KeyCredential)
{
Expand Down Expand Up @@ -132,9 +132,9 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
FileClient DirectoryClient::GetFileClient(const std::string& path) const
{
auto builder = m_dfsUri;
builder.AppendPath(path);
builder.AppendPath(Storage::Details::UrlEncodePath(path));
auto blobClient = m_blobClient;
blobClient.m_blobUrl.AppendPath(path);
blobClient.m_blobUrl.AppendPath(Storage::Details::UrlEncodePath(path));
auto blockBlobClient = blobClient.GetBlockBlobClient();
return FileClient(
std::move(builder), std::move(blobClient), std::move(blockBlobClient), m_pipeline);
Expand All @@ -143,9 +143,9 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
DirectoryClient DirectoryClient::GetSubDirectoryClient(const std::string& path) const
{
auto builder = m_dfsUri;
builder.AppendPath(path);
builder.AppendPath(Storage::Details::UrlEncodePath(path));
auto blobClient = m_blobClient;
blobClient.m_blobUrl.AppendPath(path);
blobClient.m_blobUrl.AppendPath(Storage::Details::UrlEncodePath(path));
return DirectoryClient(std::move(builder), std::move(blobClient), m_pipeline);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto fileUri = std::move(parsedConnectionString.DataLakeServiceUri);
fileUri.AppendPath(fileSystemName);
fileUri.AppendPath(filePath);
fileUri.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));
fileUri.AppendPath(Storage::Details::UrlEncodePath(filePath));

if (parsedConnectionString.KeyCredential)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto fileSystemUri = std::move(parsedConnectionString.DataLakeServiceUri);
fileSystemUri.AppendPath(fileSystemName);
fileSystemUri.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));

if (parsedConnectionString.KeyCredential)
{
Expand Down Expand Up @@ -163,15 +163,15 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
PathClient FileSystemClient::GetPathClient(const std::string& path) const
{
auto builder = m_dfsUri;
builder.AppendPath(path);
builder.AppendPath(Storage::Details::UrlEncodePath(path));
return PathClient(builder, m_blobContainerClient.GetBlobClient(path), m_pipeline);
}

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

auto builder = m_dfsUri;
builder.AppendPath(path);
builder.AppendPath(Storage::Details::UrlEncodePath(path));
auto blobClient = m_blobContainerClient.GetBlobClient(path);
auto blockBlobClient = blobClient.GetBlockBlobClient();
return FileClient(
Expand All @@ -181,7 +181,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
DirectoryClient FileSystemClient::GetDirectoryClient(const std::string& path) const
{
auto builder = m_dfsUri;
builder.AppendPath(path);
builder.AppendPath(Storage::Details::UrlEncodePath(path));
return DirectoryClient(builder, m_blobContainerClient.GetBlobClient(path), m_pipeline);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto pathUri = std::move(parsedConnectionString.DataLakeServiceUri);
pathUri.AppendPath(fileSystemName);
pathUri.AppendPath(path);
pathUri.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));
pathUri.AppendPath(Storage::Details::UrlEncodePath(path));

if (parsedConnectionString.KeyCredential)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
FileSystemClient ServiceClient::GetFileSystemClient(const std::string& fileSystemName) const
{
auto builder = m_dfsUri;
builder.AppendPath(fileSystemName);
builder.AppendPath(Storage::Details::UrlEncodePath(fileSystemName));
return FileSystemClient(
builder, m_blobServiceClient.GetBlobContainerClient(fileSystemName), m_pipeline);
}
Expand All @@ -179,8 +179,8 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake {
blobOptions.MaxResults = options.MaxResults;
auto result = m_blobServiceClient.ListBlobContainersSegment(blobOptions);
auto response = ListFileSystemsSegmentResult();
response.ContinuationToken
= result->ContinuationToken.empty() ? response.ContinuationToken : result->ContinuationToken;
response.ContinuationToken = result->ContinuationToken.empty() ? response.ContinuationToken
: result->ContinuationToken;
response.Filesystems = FileSystemsFromContainerItems(result->Items);
return Azure::Core::Response<ListFileSystemsSegmentResult>(
std::move(response), result.ExtractRawResponse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: MIT

#include "datalake_file_system_client_test.hpp"
#include "azure/storage/common/crypt.hpp"
#include "azure/storage/files/datalake/datalake_options.hpp"

#include <algorithm>
Expand Down Expand Up @@ -249,4 +250,36 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_LE(2U, response->Paths.size());
}
}

TEST_F(DataLakeFileSystemClientTest, UnencodedPathDirectoryFileNameWorks)
{
const std::string non_ascii_word = "\xE6\xB5\x8B\xE8\xAF\x95";
const std::string encoded_non_ascii_word = "%E6%B5%8B%E8%AF%95";
std::string baseName = "a b c / !@#$%^&*(?/<>,.;:'\"[]{}|`~\\) def" + non_ascii_word;
{
std::string pathName = baseName + RandomString();
auto pathClient = m_fileSystemClient->GetPathClient(pathName);
EXPECT_NO_THROW(pathClient.Create(Files::DataLake::PathResourceType::File));
auto pathUrl = pathClient.GetUri();
EXPECT_EQ(
pathUrl, m_fileSystemClient->GetUri() + "/" + Storage::Details::UrlEncodePath(pathName));
}
{
std::string directoryName = baseName + RandomString();
auto directoryClient = m_fileSystemClient->GetDirectoryClient(directoryName);
EXPECT_NO_THROW(directoryClient.Create());
auto directoryUrl = directoryClient.GetUri();
EXPECT_EQ(
directoryUrl,
m_fileSystemClient->GetUri() + "/" + Storage::Details::UrlEncodePath(directoryName));
}
{
std::string fileName = baseName + RandomString();
auto fileClient = m_fileSystemClient->GetFileClient(fileName);
EXPECT_NO_THROW(fileClient.Create());
auto fileUrl = fileClient.GetUri();
EXPECT_EQ(
fileUrl, m_fileSystemClient->GetUri() + "/" + Storage::Details::UrlEncodePath(fileName));
}
}
}}} // namespace Azure::Storage::Test
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-files-datalake/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-beta.3
1.0.0-beta.4
6 changes: 6 additions & 0 deletions sdk/storage/azure-storage-files-shares/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.0.0-beta.4

### Bug Fixes

* Unencoded Share/File/Directory name is now encoded.

## 1.0.0-beta.3 (2020-10-13)

### New Features
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/azure-storage-files-shares/src/share_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto shareUri = std::move(parsedConnectionString.FileServiceUri);
shareUri.AppendPath(shareName);
shareUri.AppendPath(Storage::Details::UrlEncodePath(shareName));

if (parsedConnectionString.KeyCredential)
{
Expand Down Expand Up @@ -115,14 +115,14 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
DirectoryClient ShareClient::GetDirectoryClient(const std::string& directoryPath) const
{
auto builder = m_shareUri;
builder.AppendPath(directoryPath);
builder.AppendPath(Storage::Details::UrlEncodePath(directoryPath));
return DirectoryClient(builder, m_pipeline);
}

FileClient ShareClient::GetFileClient(const std::string& filePath) const
{
auto builder = m_shareUri;
builder.AppendPath(filePath);
builder.AppendPath(Storage::Details::UrlEncodePath(filePath));
return FileClient(builder, m_pipeline);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto directoryUri = std::move(parsedConnectionString.FileServiceUri);
directoryUri.AppendPath(shareName);
directoryUri.AppendPath(directoryPath);
directoryUri.AppendPath(Storage::Details::UrlEncodePath(shareName));
directoryUri.AppendPath(Storage::Details::UrlEncodePath(directoryPath));

if (parsedConnectionString.KeyCredential)
{
Expand Down Expand Up @@ -118,14 +118,14 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
DirectoryClient DirectoryClient::GetSubDirectoryClient(const std::string& subDirectoryName) const
{
auto builder = m_shareDirectoryUri;
builder.AppendPath(subDirectoryName);
builder.AppendPath(Storage::Details::UrlEncodePath(subDirectoryName));
return DirectoryClient(builder, m_pipeline);
}

FileClient DirectoryClient::GetFileClient(const std::string& filePath) const
{
auto builder = m_shareDirectoryUri;
builder.AppendPath(filePath);
builder.AppendPath(Storage::Details::UrlEncodePath(filePath));
return FileClient(builder, m_pipeline);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
{
auto parsedConnectionString = Azure::Storage::Details::ParseConnectionString(connectionString);
auto fileUri = std::move(parsedConnectionString.FileServiceUri);
fileUri.AppendPath(shareName);
fileUri.AppendPath(filePath);
fileUri.AppendPath(Storage::Details::UrlEncodePath(shareName));
fileUri.AppendPath(Storage::Details::UrlEncodePath(filePath));

if (parsedConnectionString.KeyCredential)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
ShareClient ServiceClient::GetShareClient(const std::string& shareName) const
{
auto builder = m_serviceUri;
builder.AppendPath(shareName);
builder.AppendPath(Storage::Details::UrlEncodePath(shareName));
return ShareClient(builder, m_pipeline);
}

Expand Down
24 changes: 24 additions & 0 deletions sdk/storage/azure-storage-files-shares/test/share_client_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT

#include "azure/storage/common/crypt.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reformat

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know why my Clang formatter does not catch this one.

#include "share_client_test.hpp"

#include <algorithm>
Expand Down Expand Up @@ -298,4 +299,27 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_THROW(m_shareClient->Delete(), StorageError);
}

TEST_F(FileShareClientTest, UnencodedDirectoryFileNameWorks)
{
const std::string non_ascii_word = "\xE6\xB5\x8B\xE8\xAF\x95";
const std::string encoded_non_ascii_word = "%E6%B5%8B%E8%AF%95";
std::string baseName = "a b c !@#$%^&(,.;'[]{}`~) def" + non_ascii_word;

{
std::string directoryName = baseName + RandomString();
auto directoryClient = m_shareClient->GetDirectoryClient(directoryName);
EXPECT_NO_THROW(directoryClient.Create());
auto directoryUrl = directoryClient.GetUri();
EXPECT_EQ(
directoryUrl,
m_shareClient->GetUri() + "/" + Storage::Details::UrlEncodePath(directoryName));
}
{
std::string fileName = baseName + RandomString();
auto fileClient = m_shareClient->GetFileClient(fileName);
EXPECT_NO_THROW(fileClient.Create(1024));
auto fileUrl = fileClient.GetUri();
EXPECT_EQ(fileUrl, m_shareClient->GetUri() + "/" + Storage::Details::UrlEncodePath(fileName));
}
}
}}} // namespace Azure::Storage::Test
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-files-shares/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-beta.3
1.0.0-beta.4