Skip to content

Commit

Permalink
Escaping % (percent sign) segment in Uri.AppendToPath (#12369)
Browse files Browse the repository at this point in the history
* Escaping % percent sign in segment in AppendToPath
  • Loading branch information
amnguye authored Jun 3, 2020
1 parent 4c5adff commit ed7c9cf
Show file tree
Hide file tree
Showing 86 changed files with 10,620 additions and 1,534 deletions.
44 changes: 44 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/AppendBlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,50 @@ await TestHelper.AssertExpectedExceptionAsync<ArgumentNullException>(
}
}

[Test]
public async Task GetAppendBlobClient_AsciiName()
{
//Arrange
await using DisposingContainer test = await GetTestContainerAsync();
string blobName = GetNewBlobName();

//Act
AppendBlobClient blob = test.Container.GetAppendBlobClient(blobName);
await blob.CreateAsync();

//Assert
List<string> names = new List<string>();
await foreach (BlobItem pathItem in test.Container.GetBlobsAsync())
{
names.Add(pathItem.Name);
}
// Verify the file name exists in the filesystem
Assert.AreEqual(1, names.Count);
Assert.Contains(blobName, names);
}

[Test]
public async Task GetAppendBlobClient_NonAsciiName()
{
//Arrange
await using DisposingContainer test = await GetTestContainerAsync();
string blobName = GetNewNonAsciiBlobName();

//Act
AppendBlobClient blob = test.Container.GetAppendBlobClient(blobName);
await blob.CreateAsync();

//Assert
List<string> names = new List<string>();
await foreach (BlobItem pathItem in test.Container.GetBlobsAsync())
{
names.Add(pathItem.Name);
}
// Verify the file name exists in the filesystem
Assert.AreEqual(1, names.Count);
Assert.Contains(blobName, names);
}

private AppendBlobRequestConditions BuildDestinationAccessConditions(
AccessConditionParameters parameters,
bool lease = false,
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Azure.Storage.Blobs/tests/BlobTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public BlobTestBase(bool async, BlobClientOptions.ServiceVersion serviceVersion,
public string GetNewContainerName() => $"test-container-{Recording.Random.NewGuid()}";
public string GetNewBlobName() => $"test-blob-{Recording.Random.NewGuid()}";
public string GetNewBlockName() => $"test-block-{Recording.Random.NewGuid()}";
public string GetNewNonAsciiBlobName() => $"test-⣩þ‽-{Recording.Random.NewGuid()}";
public string GetNewNonAsciiBlobName() => $"test-⣩þ‽%3A-{Recording.Random.NewGuid()}";

public BlobClientOptions GetOptions(bool parallelRange = false)
{
Expand Down
53 changes: 53 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/BlockBlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,59 @@ await blob.UploadAsync(
Assert.AreEqual(blobSize, progress.List[progress.List.Count - 1]);
}


[Test]
public async Task GetBlockBlobClient_AsciiName()
{
//Arrange
await using DisposingContainer test = await GetTestContainerAsync();
string blobName = GetNewBlobName();

//Act
BlockBlobClient blob = test.Container.GetBlockBlobClient(blobName);
var data = GetRandomBuffer(Size);
using (var stream = new MemoryStream(data))
{
await blob.UploadAsync(content: stream);
}

//Assert
List<string> names = new List<string>();
await foreach (BlobItem pathItem in test.Container.GetBlobsAsync())
{
names.Add(pathItem.Name);
}
// Verify the file name exists in the filesystem
Assert.AreEqual(1, names.Count);
Assert.Contains(blobName, names);
}

[Test]
public async Task GetBlockBlobClient_NonAsciiName()
{
//Arrange
await using DisposingContainer test = await GetTestContainerAsync();
string blobName = GetNewNonAsciiBlobName();

//Act
BlockBlobClient blob = test.Container.GetBlockBlobClient(blobName);
var data = GetRandomBuffer(Size);
using (var stream = new MemoryStream(data))
{
await blob.UploadAsync(content: stream);
}

//Assert
List<string> names = new List<string>();
await foreach (BlobItem pathItem in test.Container.GetBlobsAsync())
{
names.Add(pathItem.Name);
}
// Verify the file name exists in the filesystem
Assert.AreEqual(1, names.Count);
Assert.Contains(blobName, names);
}

private RequestConditions BuildRequestConditions(AccessConditionParameters parameters)
=> new RequestConditions
{
Expand Down
44 changes: 44 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/PageBlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,50 @@ await TestHelper.AssertExpectedExceptionAsync<RequestFailedException>(
});
}

[Test]
public async Task GetPageBlobClient_AsciiName()
{
//Arrange
await using DisposingContainer test = await GetTestContainerAsync();
string blobName = GetNewBlobName();

//Act
PageBlobClient blob = test.Container.GetPageBlobClient(blobName);
await blob.CreateAsync(Constants.KB);

//Assert
List<string> names = new List<string>();
await foreach (BlobItem pathItem in test.Container.GetBlobsAsync())
{
names.Add(pathItem.Name);
}
// Verify the file name exists in the filesystem
Assert.AreEqual(1, names.Count);
Assert.Contains(blobName, names);
}

[Test]
public async Task GetPageBlobClient_NonAsciiName()
{
//Arrange
await using DisposingContainer test = await GetTestContainerAsync();
string blobName = GetNewNonAsciiBlobName();

//Act
PageBlobClient blob = test.Container.GetPageBlobClient(blobName);
await blob.CreateAsync(Constants.KB);

//Assert
List<string> names = new List<string>();
await foreach (BlobItem pathItem in test.Container.GetBlobsAsync())
{
names.Add(pathItem.Name);
}
// Verify the file name exists in the filesystem
Assert.AreEqual(1, names.Count);
Assert.Contains(blobName, names);
}

private PageBlobRequestConditions BuildAccessConditions(
AccessConditionParameters parameters,
bool lease = false,
Expand Down
Loading

0 comments on commit ed7c9cf

Please sign in to comment.