Skip to content

Commit b157814

Browse files
bugfix and add test for %
1 parent a106c64 commit b157814

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public CloudStoragePath getPath(URI uri) {
212212

213213
/** Convenience method: replaces spaces with "%20", builds a URI, and calls getPath(uri). */
214214
public CloudStoragePath getPath(String uriInStringForm) {
215-
String escaped = UrlEscapers.urlFragmentEscaper().escape("gs://bucket/with/a space");
215+
String escaped = UrlEscapers.urlFragmentEscaper().escape(uriInStringForm);
216216
return getPath(URI.create(escaped));
217217
}
218218

google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProviderTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.IOException;
4242
import java.io.InputStream;
4343
import java.io.OutputStream;
44+
import java.io.UnsupportedEncodingException;
4445
import java.net.URI;
4546
import java.nio.ByteBuffer;
4647
import java.nio.channels.ReadableByteChannel;
@@ -646,7 +647,7 @@ public void testProviderEquals() {
646647
}
647648

648649
@Test
649-
public void testFromSpace() {
650+
public void testFromSpace() throws UnsupportedEncodingException {
650651
// User should be able to create paths to files whose name contains a space.
651652
// Traditional way 1: manually escape the spaces
652653
Path path1 = Paths.get(URI.create("gs://bucket/with/a%20space"));
@@ -663,6 +664,11 @@ public void testFromSpace() {
663664
assertThat(path2.getFileSystem().provider()).isEqualTo(path3.getFileSystem().provider());
664665
assertThat(path1.toUri()).isEqualTo(path2.toUri());
665666
assertThat(path2.toUri()).isEqualTo(path3.toUri());
667+
668+
Path path4 = provider.getPath("gs://bucket/with/a%20percent");
669+
String toString = path4.toString();
670+
assertThat(toString).doesNotContain(" ");
671+
assertThat(toString).contains("%");
666672
}
667673

668674
private static CloudStorageConfiguration permitEmptyPathComponents(boolean value) {

google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/CloudStoragePathTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ public void testSpaces() throws IOException {
494494
// we can also go via a URI. Decoding should give us the space back.
495495
String toUri = URLDecoder.decode(path.toUri().toString(), "UTF-8");
496496
assertThat(toUri).contains(" ");
497+
498+
Path path2 = fs.getPath("/with/a%20percent");
499+
String toUri2 = URLDecoder.decode(path2.toUri().toString(), "UTF-8");
500+
assertThat(toUri2).doesNotContain(" ");
501+
assertThat(toUri2).contains("%");
497502
}
498503
}
499504

0 commit comments

Comments
 (0)