Skip to content

Commit 03e2b94

Browse files
authored
Decode values in object listing if encoding is set (#1183)
1 parent 12f0ed4 commit 03e2b94

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

api/src/main/java/io/minio/messages/ListBucketResultV1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public class ListBucketResultV1 extends ListObjectsResult {
3939
private List<Contents> contents;
4040

4141
public String marker() {
42-
return marker;
42+
return decodeIfNeeded(marker);
4343
}
4444

4545
public String nextMarker() {
46-
return nextMarker;
46+
return decodeIfNeeded(nextMarker);
4747
}
4848

4949
@Override

api/src/main/java/io/minio/messages/ListBucketResultV2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public int keyCount() {
5252

5353
/** Returns start after. */
5454
public String startAfter() {
55-
return startAfter;
55+
return decodeIfNeeded(startAfter);
5656
}
5757

5858
/** Returns continuation token. */

api/src/main/java/io/minio/messages/ListMultipartUploadsResult.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package io.minio.messages;
1818

19+
import java.io.UnsupportedEncodingException;
20+
import java.net.URLDecoder;
21+
import java.nio.charset.StandardCharsets;
1922
import java.util.Collections;
2023
import java.util.LinkedList;
2124
import java.util.List;
@@ -35,6 +38,9 @@ public class ListMultipartUploadsResult {
3538
@Element(name = "Bucket")
3639
private String bucketName;
3740

41+
@Element(name = "EncodingType", required = false)
42+
private String encodingType;
43+
3844
@Element(name = "KeyMarker", required = false)
3945
private String keyMarker;
4046

@@ -58,6 +64,17 @@ public class ListMultipartUploadsResult {
5864

5965
public ListMultipartUploadsResult() {}
6066

67+
private String decodeIfNeeded(String value) {
68+
try {
69+
return (value != null && "url".equals(encodingType))
70+
? URLDecoder.decode(value, StandardCharsets.UTF_8.name())
71+
: value;
72+
} catch (UnsupportedEncodingException e) {
73+
// This never happens as 'enc' name comes from JDK's own StandardCharsets.
74+
throw new RuntimeException(e);
75+
}
76+
}
77+
6178
/** Returns whether the result is truncated or not. */
6279
public boolean isTruncated() {
6380
return isTruncated;
@@ -70,7 +87,7 @@ public String bucketName() {
7087

7188
/** Returns key marker. */
7289
public String keyMarker() {
73-
return keyMarker;
90+
return decodeIfNeeded(keyMarker);
7491
}
7592

7693
/** Returns upload ID marker. */
@@ -80,7 +97,7 @@ public String uploadIdMarker() {
8097

8198
/** Returns next key marker. */
8299
public String nextKeyMarker() {
83-
return nextKeyMarker;
100+
return decodeIfNeeded(nextKeyMarker);
84101
}
85102

86103
/** Returns next upload ID marker. */
@@ -93,6 +110,10 @@ public int maxUploads() {
93110
return maxUploads;
94111
}
95112

113+
public String encodingType() {
114+
return encodingType;
115+
}
116+
96117
/** Returns List of Upload. */
97118
public List<Upload> uploads() {
98119
if (uploads == null) {

api/src/main/java/io/minio/messages/ListObjectsResult.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package io.minio.messages;
1818

1919
import com.google.common.base.MoreObjects;
20+
import java.io.UnsupportedEncodingException;
21+
import java.net.URLDecoder;
22+
import java.nio.charset.StandardCharsets;
2023
import java.util.Collections;
2124
import java.util.LinkedList;
2225
import java.util.List;
@@ -54,6 +57,17 @@ public abstract class ListObjectsResult {
5457

5558
public ListObjectsResult() {}
5659

60+
protected String decodeIfNeeded(String value) {
61+
try {
62+
return (value != null && "url".equals(encodingType))
63+
? URLDecoder.decode(value, StandardCharsets.UTF_8.name())
64+
: value;
65+
} catch (UnsupportedEncodingException e) {
66+
// This never happens as 'enc' name comes from JDK's own StandardCharsets.
67+
throw new RuntimeException(e);
68+
}
69+
}
70+
5771
/** Returns bucket name. */
5872
public String name() {
5973
return name;
@@ -65,7 +79,7 @@ public String encodingType() {
6579

6680
/** Returns prefix. */
6781
public String prefix() {
68-
return prefix;
82+
return decodeIfNeeded(prefix);
6983
}
7084

7185
/** Returns delimiter. */

api/src/main/java/io/minio/messages/ListVersionsResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public class ListVersionsResult extends ListObjectsResult {
4949
private List<DeleteMarker> deleteMarkers;
5050

5151
public String keyMarker() {
52-
return keyMarker;
52+
return decodeIfNeeded(keyMarker);
5353
}
5454

5555
public String nextKeyMarker() {
56-
return nextKeyMarker;
56+
return decodeIfNeeded(nextKeyMarker);
5757
}
5858

5959
public String versionIdMarker() {

api/src/main/java/io/minio/messages/Upload.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package io.minio.messages;
1818

19+
import java.io.UnsupportedEncodingException;
20+
import java.net.URLDecoder;
21+
import java.nio.charset.StandardCharsets;
1922
import java.time.ZonedDateTime;
2023
import org.simpleframework.xml.Element;
2124
import org.simpleframework.xml.Namespace;
@@ -47,12 +50,20 @@ public class Upload {
4750
private ResponseDate initiated;
4851

4952
private long aggregatedPartSize;
53+
private String encodingType = null;
5054

5155
public Upload() {}
5256

5357
/** Returns object name. */
5458
public String objectName() {
55-
return objectName;
59+
try {
60+
return "url".equals(encodingType)
61+
? URLDecoder.decode(objectName, StandardCharsets.UTF_8.name())
62+
: objectName;
63+
} catch (UnsupportedEncodingException e) {
64+
// This never happens as 'enc' name comes from JDK's own StandardCharsets.
65+
throw new RuntimeException(e);
66+
}
5667
}
5768

5869
/** Returns upload ID. */
@@ -89,4 +100,8 @@ public long aggregatedPartSize() {
89100
public void setAggregatedPartSize(long size) {
90101
this.aggregatedPartSize = size;
91102
}
103+
104+
public void setEncodingType(String encodingType) {
105+
this.encodingType = encodingType;
106+
}
92107
}

0 commit comments

Comments
 (0)