JCLOUDS-217: Percent encoding changes.

jclouds should not check if the string is encoded, but rather expect
that all strings would be encoded prior to transmission. As part of
that change, we must make sure that no code relies on such behavior
within jclouds. This commit adds a blobstore test to check encoding
pattern for blobs. It also removes the encoding check in the Strings2
class and the related test.
This commit is contained in:
Timur Alperovich 2015-08-21 15:12:05 -07:00
parent 9be7339c32
commit aaa164179c
4 changed files with 29 additions and 14 deletions

View File

@ -47,6 +47,7 @@ import org.jclouds.blobstore.domain.ContainerAccess;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -561,7 +562,31 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
}
}
private void checkEqualNames(ImmutableSet<String> expectedSet, PageSet<? extends StorageMetadata> results) {
@DataProvider
public Object[][] getBlobsToEscape() {
ImmutableSet<String> testNames = ImmutableSet.of("%20", "%20 ", " %20", " ");
Object[][] result = new Object[1][1];
result[0][0] = testNames;
return result;
}
@Test(dataProvider = "getBlobsToEscape", groups = {"integration", "live"})
public void testBlobNameEscaping(Set<String> blobNames) throws InterruptedException {
final String containerName = getContainerName();
BlobStore blobStore = view.getBlobStore();
try {
for (String name : blobNames) {
Blob blob = blobStore.blobBuilder(name).payload(ByteSource.wrap("test".getBytes())).contentLength(4)
.build();
blobStore.putBlob(containerName, blob);
}
checkEqualNames(blobNames, blobStore.list(containerName));
} finally {
returnContainer(containerName);
}
}
private void checkEqualNames(Set<String> expectedSet, PageSet<? extends StorageMetadata> results) {
Set<String> names = new HashSet<String>();
for (StorageMetadata sm : results) {
names.add(sm.getName());

View File

@ -144,7 +144,6 @@ public final class Uris {
}
public UriBuilder appendPath(String path) {
path = urlDecode(checkNotNull(path, "path"));
if (this.path == null) {
path(path);
} else {

View File

@ -53,8 +53,6 @@ public class Strings2 {
}
public static String urlEncode(String in, Iterable<Character> skipEncode) {
if (isUrlEncoded(in))
return in;
try {
String returnVal = URLEncoder.encode(in, "UTF-8");
returnVal = returnVal.replace("+", "%20");
@ -109,11 +107,10 @@ public class Strings2 {
public static String urlDecode(@Nullable String in) {
if (in == null)
return null;
String input = in.toString();
// Don't double decode
if (!isUrlEncoded(input)) {
return input;
if (!isUrlEncoded(in)) {
return in;
}
String input = in.toString();
try {
return URLDecoder.decode(input, "UTF-8");
} catch (UnsupportedEncodingException e) {

View File

@ -32,12 +32,6 @@ public class Strings2Test {
assert !Strings2.isUrlEncoded("/read-tests/ tep");
}
public void testNoDoubleEncode() {
assertEquals(urlEncode("/read-tests/%73%6f%6d%65%20%66%69%6c%65", '/'),
"/read-tests/%73%6f%6d%65%20%66%69%6c%65");
assertEquals(urlEncode("/read-tests/ tep", '/'), "/read-tests/%20tep");
}
public void testNoDoubleDecode() {
assertEquals(urlDecode("foo%20bar%2Bbaz"), "foo bar+baz");
assertEquals(urlDecode("foo bar+baz"), "foo bar+baz");