Skip to content

Commit

Permalink
Fix objects with spaces in name not returned correctly fixes #1100 (#…
Browse files Browse the repository at this point in the history
…1101)

* Fix objects with spaces in name not returned correctly (#1100)

The Uri.UnescapeDataString method has been replaced with the HttpUtility.UrlDecode method in the BucketOperations.cs file to correctly decode the URL. Additionally, the ListObjects_Test7 function has been added to the Program.cs and FunctionalTest.cs files to test whether ListObjects lists all objects matching a prefix with a space in a non-recursive manner.

* fix formatting

* Add test for prefix with a plus character

* fix formatting

---------

Co-authored-by: Edwin Goddard <goddarde@phonovation.com>
  • Loading branch information
heedfull and Edwin Goddard authored Jun 13, 2024
1 parent e7b4d78 commit 7a6533d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
88 changes: 88 additions & 0 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5292,6 +5292,94 @@ internal static async Task ListObjects_Test6(IMinioClient minio)
}
}

internal static async Task ListObjects_Test7(IMinioClient minio)
{
var startTime = DateTime.Now;
var bucketName = GetRandomName(15);
var prefix = "minix ";
var objectName = prefix + GetRandomName(10);
var args = new Dictionary<string, string>
(StringComparer.Ordinal)
{
{ "bucketName", bucketName },
{ "objectName", objectName },
{ "prefix", prefix },
{ "recursive", "false" }
};
try
{
await Setup_Test(minio, bucketName).ConfigureAwait(false);
var tasks = new Task[2];
for (var i = 0; i < 2; i++)
tasks[i] = PutObject_Task(minio, bucketName, objectName + i, null, null, 0, null,
rsg.GenerateStreamFromSeed(1));

await Task.WhenAll(tasks).ConfigureAwait(false);

await ListObjects_Test(minio, bucketName, prefix, 2, false).ConfigureAwait(false);
new MintLogger("ListObjects_Test7", listObjectsSignature,
"Tests whether ListObjects lists all objects matching a prefix with a space non-recursive",
TestStatus.PASS,
DateTime.Now - startTime, args: args).Log();
}
catch (Exception ex)
{
new MintLogger("ListObjects_Test7", listObjectsSignature,
"Tests whether ListObjects lists all objects matching a prefix with a space non-recursive",
TestStatus.FAIL,
DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
}
finally
{
await TearDown(minio, bucketName).ConfigureAwait(false);
}
}

internal static async Task ListObjects_Test8(IMinioClient minio)
{
var startTime = DateTime.Now;
var bucketName = GetRandomName(15);
var prefix = "minix+";
var objectName = prefix + GetRandomName(10);
var args = new Dictionary<string, string>
(StringComparer.Ordinal)
{
{ "bucketName", bucketName },
{ "objectName", objectName },
{ "prefix", prefix },
{ "recursive", "false" }
};
try
{
await Setup_Test(minio, bucketName).ConfigureAwait(false);
var tasks = new Task[2];
for (var i = 0; i < 2; i++)
tasks[i] = PutObject_Task(minio, bucketName, objectName + i, null, null, 0, null,
rsg.GenerateStreamFromSeed(1));

await Task.WhenAll(tasks).ConfigureAwait(false);

await ListObjects_Test(minio, bucketName, prefix, 2, false).ConfigureAwait(false);
new MintLogger("ListObjects_Test8", listObjectsSignature,
"Tests whether ListObjects lists all objects matching a prefix with a plus non-recursive",
TestStatus.PASS,
DateTime.Now - startTime, args: args).Log();
}
catch (Exception ex)
{
new MintLogger("ListObjects_Test8", listObjectsSignature,
"Tests whether ListObjects lists all objects matching a prefix with a plus non-recursive",
TestStatus.FAIL,
DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
}
finally
{
await TearDown(minio, bucketName).ConfigureAwait(false);
}
}

internal static async Task ListObjectVersions_Test1(IMinioClient minio)
{
var startTime = DateTime.Now;
Expand Down
2 changes: 2 additions & 0 deletions Minio.Functional.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ public static async Task Main(string[] args)
functionalTestTasks.Add(FunctionalTest.ListObjects_Test4(minioClient));
functionalTestTasks.Add(FunctionalTest.ListObjects_Test5(minioClient));
functionalTestTasks.Add(FunctionalTest.ListObjects_Test6(minioClient));
functionalTestTasks.Add(FunctionalTest.ListObjects_Test7(minioClient));
functionalTestTasks.Add(FunctionalTest.ListObjects_Test8(minioClient));

// Test RemoveObjectAsync function
functionalTestTasks.Add(FunctionalTest.RemoveObject_Test1(minioClient));
Expand Down
3 changes: 2 additions & 1 deletion Minio/ApiEndpoints/BucketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Net;
using System.Reactive.Linq;
using System.Runtime.CompilerServices;
using System.Web;
using System.Xml.Linq;
using CommunityToolkit.HighPerformance;
using Minio.ApiEndpoints;
Expand Down Expand Up @@ -271,7 +272,7 @@ public async IAsyncEnumerable<Item> ListObjectsEnumAsync(ListObjectsArgs args,
var objectKey = t.Element(ns + "Key")?.Value;
if (objectKey != null)
objectKey = Uri.UnescapeDataString(objectKey);
objectKey = HttpUtility.UrlDecode(objectKey);
return new Item
{
Expand Down

0 comments on commit 7a6533d

Please sign in to comment.