Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
tanyasethi-msft committed Feb 1, 2024
commit fc24832505ec687464f916d65613b9dde31b4bdd
2 changes: 1 addition & 1 deletion sdk/storage/azdatalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
### Breaking Changes

### Bugs Fixed
* Escape paths for NewDirectoryClient and New FileClient in a file system
* Escape paths for NewDirectoryClient and NewFileClient in a file system. Fixes [#22281](https://github.com/Azure/azure-sdk-for-go/issues/22281).

### Other Changes

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azdatalake/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/storage/azdatalake",
"Tag": "go/storage/azdatalake_9977ab7169"
"Tag": "go/storage/azdatalake_05091fc1bd"
}
23 changes: 2 additions & 21 deletions sdk/storage/azdatalake/filesystem/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/internal/shared"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake/sas"
"net/http"
"net/url"
"strings"
"time"
)
Expand Down Expand Up @@ -203,15 +202,7 @@ func (fs *Client) BlobURL() string {
// The new directory.Client uses the same request policy pipeline as the Client.
func (fs *Client) NewDirectoryClient(directoryPath string) *directory.Client {
directoryPath = strings.ReplaceAll(directoryPath, "\\", "/")
names := strings.Split(directoryPath, "/")
path := ""
for i, name := range names {
if i > 0 {
path += "/"
}
path += url.PathEscape(name)
}
dirURL := runtime.JoinPaths(fs.generatedFSClientWithDFS().Endpoint(), path)
dirURL := runtime.JoinPaths(fs.generatedFSClientWithDFS().Endpoint(), escapeSplitPaths(directoryPath))
blobURL, dirURL := shared.GetURLs(dirURL)
return (*directory.Client)(base.NewPathClient(dirURL, blobURL, fs.containerClient().NewBlockBlobClient(directoryPath), fs.generatedFSClientWithDFS().InternalClient().WithClientName(exported.ModuleName), fs.sharedKey(), fs.identityCredential(), fs.getClientOptions()))
}
Expand All @@ -220,17 +211,7 @@ func (fs *Client) NewDirectoryClient(directoryPath string) *directory.Client {
// The new file.Client uses the same request policy pipeline as the Client.
func (fs *Client) NewFileClient(filePath string) *file.Client {
filePath = strings.ReplaceAll(filePath, "\\", "/")

names := strings.Split(filePath, "/")
path := ""
for i, name := range names {
if i > 0 {
path += "/"
}
path += url.PathEscape(name)

}
fileURL := runtime.JoinPaths(fs.generatedFSClientWithDFS().Endpoint(), path)
fileURL := runtime.JoinPaths(fs.generatedFSClientWithDFS().Endpoint(), escapeSplitPaths(filePath))
blobURL, fileURL := shared.GetURLs(fileURL)
return (*file.Client)(base.NewPathClient(fileURL, blobURL, fs.containerClient().NewBlockBlobClient(filePath), fs.generatedFSClientWithDFS().InternalClient().WithClientName(exported.ModuleName), fs.sharedKey(), fs.identityCredential(), fs.getClientOptions()))
}
Expand Down
6 changes: 5 additions & 1 deletion sdk/storage/azdatalake/filesystem/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ func (s *RecordedTestSuite) TestCreateFileSystemFileClientWithSpecialFileName()
_, err = fsClient.Create(context.Background(), nil)
_require.NoError(err)

fileClient := fsClient.NewFileClient("#,%,?")
fileClient := fsClient.NewFileClient("#,%,?/#")
_require.NoError(err)

response, err := fileClient.Create(context.Background(), nil)
Expand All @@ -1370,6 +1370,10 @@ func (s *RecordedTestSuite) TestCreateFileSystemFileClientWithSpecialFileName()
owner := "4cf4e284-f6a8-4540-b53e-c3469af032dc"
_, err = fileClient.SetAccessControl(context.Background(), &file.SetAccessControlOptions{Owner: &owner})
_require.NoError(err)

// Perform an operation on blob endpoint
_, err = fileClient.SetMetadata(context.Background(), testcommon.BasicMetadata, nil)
_require.NoError(err)
}

func (s *RecordedTestSuite) TestFilesystemListPathsWithRecursive() {
Expand Down
23 changes: 23 additions & 0 deletions sdk/storage/azdatalake/filesystem/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//go:build go1.18
// +build go1.18

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package filesystem

import (
"net/url"
"strings"
)

// escapeSplitPaths is utility function to escape the individual strings by eliminating "/" in the path
func escapeSplitPaths(filePath string) string {
names := strings.Split(filePath, "/")
path := make([]string, len(names))
for i, name := range names {
path[i] = url.PathEscape(name)
}
escapedPathUrl := strings.Join(path, "/")
return escapedPathUrl
}