Skip to content

Commit

Permalink
HDDS-8183. Fix edge case where delimiter is empty string in BucketEnd…
Browse files Browse the repository at this point in the history
…point#get (#4410)
  • Loading branch information
ivandika3 committed Mar 17, 2023
1 parent 6c18d95 commit 864ec70
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.apache.hadoop.ozone.s3.commontypes;

import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -45,7 +47,7 @@ public String getName() {
*/
@Nullable public static EncodingTypeObject createNullable(
@Nullable String name, @Nullable String encodingType) {
if (name == null) {
if (StringUtils.isEmpty(name)) {
return null;
}
return new EncodingTypeObject(name, encodingType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public Response get(
String relativeKeyName = next.getName().substring(prefix.length());

int depth = StringUtils.countMatches(relativeKeyName, delimiter);
if (delimiter != null) {
if (!StringUtils.isEmpty(delimiter)) {
if (depth > 0) {
// means key has multiple delimiters in its value.
// ex: dir/dir1/dir2, where delimiter is "/" and prefix is dir/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,35 @@ public void listWithPrefixAndDelimiter2() throws OS3Exception, IOException {

}

@Test
public void listWithPrefixAndEmptyStrDelimiter()
throws OS3Exception, IOException {
BucketEndpoint getBucket = new BucketEndpoint();

OzoneClient ozoneClient =
createClientWithKeys("dir1/", "dir1/dir2/", "dir1/dir2/file1",
"dir1/dir2/file2");

getBucket.setClient(ozoneClient);

// Should behave the same if delimiter is null
ListObjectResponse getBucketResponse =
(ListObjectResponse) getBucket.get("b1", "", null, null, 100, "dir1/",
null, null, null, null, null).getEntity();

Assert.assertEquals(0, getBucketResponse.getCommonPrefixes().size());
Assert.assertEquals(4, getBucketResponse.getContents().size());
Assert.assertEquals("dir1/",
getBucketResponse.getContents().get(0).getKey().getName());
Assert.assertEquals("dir1/dir2/",
getBucketResponse.getContents().get(1).getKey().getName());
Assert.assertEquals("dir1/dir2/file1",
getBucketResponse.getContents().get(2).getKey().getName());
Assert.assertEquals("dir1/dir2/file2",
getBucketResponse.getContents().get(3).getKey().getName());

}

@Test
public void listWithContinuationToken() throws OS3Exception, IOException {

Expand Down

0 comments on commit 864ec70

Please sign in to comment.