Roded Bahat created JCLOUDS-1524:
------------------------------------

             Summary: BlobStore list fails for a prefix with special characters 
due to URL decoding
                 Key: JCLOUDS-1524
                 URL: https://issues.apache.org/jira/browse/JCLOUDS-1524
             Project: jclouds
          Issue Type: Bug
            Reporter: Roded Bahat


When calling AWS S3 BlobStore.list with a prefix containing unknown URL 
encoding parameters the following exception occurs:

{noformat}
java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in 
escape (%) pattern - For input string: "Ms"
        at java.net.URLDecoder.decode(URLDecoder.java:194)
        at org.jclouds.util.Strings2.urlDecode(Strings2.java:131)
        at 
org.jclouds.http.utils.Queries.parseKeyValueFromStringToDecodedMap(Queries.java:61)
        at org.jclouds.http.utils.Queries.access$000(Queries.java:30)
        at org.jclouds.http.utils.Queries$1.apply(Queries.java:45)
        at org.jclouds.http.utils.Queries$1.apply(Queries.java:32)
        at 
org.jclouds.aws.s3.filters.AWSRequestAuthorizeSignatureV4.signForAuthorizationHeader(AWSRequestAuthorizeSignatureV4.java:56)
        at 
org.jclouds.s3.filters.RequestAuthorizeSignatureV4.filter(RequestAuthorizeSignatureV4.java:55)
        at 
org.jclouds.http.internal.BaseHttpCommandExecutorService.invoke(BaseHttpCommandExecutorService.java:90)
        at 
org.jclouds.rest.internal.InvokeHttpMethod.invoke(InvokeHttpMethod.java:91)
        at 
org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:74)
        at 
org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:45)
        at 
org.jclouds.rest.internal.DelegatesToInvocationFunction.handle(DelegatesToInvocationFunction.java:156)
        at 
org.jclouds.rest.internal.DelegatesToInvocationFunction.invoke(DelegatesToInvocationFunction.java:123)
        at com.sun.proxy.$Proxy42.listBucket(Unknown Source)
        at org.jclouds.s3.blobstore.S3BlobStore.list(S3BlobStore.java:177)
{noformat}

To reproduce:

{noformat}
public class X {

    public static void main(String[] args) {
        BlobStoreContext blobStoreContext =
            ContextBuilder.newBuilder("s3")
                .endpoint("miniohost")
                .credentials("...", "...")
                .buildView(BlobStoreContext.class);
            // ContextBuilder.newBuilder("aws-s3")
            //     .endpoint("https://s3.amazonaws.com";)
            //     .credentials("...", "...")
            //     .buildView(BlobStoreContext.class);
        BlobStore blobStore = blobStoreContext.getBlobStore();
        String prefix = "myblob%Msuffix";
        blobStore.putBlob("roded-data", 
blobStore.blobBuilder(prefix).payload("mypayload").build());

        // This fails due to a URL decoding exception:
        try {
            blobStore.list("roded-data", 
ListContainerOptions.Builder.prefix(prefix));
        } catch (Exception e) {
            e.printStackTrace();
        }

        // This works on minio, but no results are returned.
        // It fails on AWS due to a signature mismatch error.
        try {
            PageSet<? extends StorageMetadata> list = blobStore
                .list("roded-data", Builder.prefix(URLEncoder.encode(prefix, 
"UTF-8")));
            assert !list.isEmpty();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
{noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to