Skip to content

Commit

Permalink
Decode values in object listing if encoding is set (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana authored Apr 19, 2021
1 parent 12f0ed4 commit 03e2b94
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/io/minio/messages/ListBucketResultV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public class ListBucketResultV1 extends ListObjectsResult {
private List<Contents> contents;

public String marker() {
return marker;
return decodeIfNeeded(marker);
}

public String nextMarker() {
return nextMarker;
return decodeIfNeeded(nextMarker);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public int keyCount() {

/** Returns start after. */
public String startAfter() {
return startAfter;
return decodeIfNeeded(startAfter);
}

/** Returns continuation token. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.minio.messages;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -35,6 +38,9 @@ public class ListMultipartUploadsResult {
@Element(name = "Bucket")
private String bucketName;

@Element(name = "EncodingType", required = false)
private String encodingType;

@Element(name = "KeyMarker", required = false)
private String keyMarker;

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

public ListMultipartUploadsResult() {}

private String decodeIfNeeded(String value) {
try {
return (value != null && "url".equals(encodingType))
? URLDecoder.decode(value, StandardCharsets.UTF_8.name())
: value;
} catch (UnsupportedEncodingException e) {
// This never happens as 'enc' name comes from JDK's own StandardCharsets.
throw new RuntimeException(e);
}
}

/** Returns whether the result is truncated or not. */
public boolean isTruncated() {
return isTruncated;
Expand All @@ -70,7 +87,7 @@ public String bucketName() {

/** Returns key marker. */
public String keyMarker() {
return keyMarker;
return decodeIfNeeded(keyMarker);
}

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

/** Returns next key marker. */
public String nextKeyMarker() {
return nextKeyMarker;
return decodeIfNeeded(nextKeyMarker);
}

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

public String encodingType() {
return encodingType;
}

/** Returns List of Upload. */
public List<Upload> uploads() {
if (uploads == null) {
Expand Down
16 changes: 15 additions & 1 deletion api/src/main/java/io/minio/messages/ListObjectsResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package io.minio.messages;

import com.google.common.base.MoreObjects;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -54,6 +57,17 @@ public abstract class ListObjectsResult {

public ListObjectsResult() {}

protected String decodeIfNeeded(String value) {
try {
return (value != null && "url".equals(encodingType))
? URLDecoder.decode(value, StandardCharsets.UTF_8.name())
: value;
} catch (UnsupportedEncodingException e) {
// This never happens as 'enc' name comes from JDK's own StandardCharsets.
throw new RuntimeException(e);
}
}

/** Returns bucket name. */
public String name() {
return name;
Expand All @@ -65,7 +79,7 @@ public String encodingType() {

/** Returns prefix. */
public String prefix() {
return prefix;
return decodeIfNeeded(prefix);
}

/** Returns delimiter. */
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/minio/messages/ListVersionsResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public class ListVersionsResult extends ListObjectsResult {
private List<DeleteMarker> deleteMarkers;

public String keyMarker() {
return keyMarker;
return decodeIfNeeded(keyMarker);
}

public String nextKeyMarker() {
return nextKeyMarker;
return decodeIfNeeded(nextKeyMarker);
}

public String versionIdMarker() {
Expand Down
17 changes: 16 additions & 1 deletion api/src/main/java/io/minio/messages/Upload.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.minio.messages;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
Expand Down Expand Up @@ -47,12 +50,20 @@ public class Upload {
private ResponseDate initiated;

private long aggregatedPartSize;
private String encodingType = null;

public Upload() {}

/** Returns object name. */
public String objectName() {
return objectName;
try {
return "url".equals(encodingType)
? URLDecoder.decode(objectName, StandardCharsets.UTF_8.name())
: objectName;
} catch (UnsupportedEncodingException e) {
// This never happens as 'enc' name comes from JDK's own StandardCharsets.
throw new RuntimeException(e);
}
}

/** Returns upload ID. */
Expand Down Expand Up @@ -89,4 +100,8 @@ public long aggregatedPartSize() {
public void setAggregatedPartSize(long size) {
this.aggregatedPartSize = size;
}

public void setEncodingType(String encodingType) {
this.encodingType = encodingType;
}
}

0 comments on commit 03e2b94

Please sign in to comment.