Skip to content

Commit

Permalink
SNOW-608673 Decode prefix when call listNextBatchOfVersions (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-schen authored Jul 6, 2022
2 parents 48aeaf3 + 2f81d77 commit 32c76a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ public List<S3VersionSummary> listVersions(String bucketName, String key, boolea
for (S3VersionSummary version : s3Summaries) {
version.setKey(URLDecoder.decode(version.getKey(), ENCODING));
}
if (prefix != null) {
vl.setPrefix(URLDecoder.decode(prefix, ENCODING));
}
String urlEncodedNextKeyMarker = vl.getNextKeyMarker();
if (null != urlEncodedNextKeyMarker) {
String decodedMarker = URLDecoder.decode(urlEncodedNextKeyMarker, ENCODING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ void listNextBatchOfVersions() throws IOException {
updatePrefixForTestCase(TestUtils.OPERATIONS.LIST_VERSIONS);
// upload same file multiple times, to generate different versions
File file = new File(EnvConstants.LOCAL_FILE_PATH_2);
String filePath = prefix + "/" + EnvConstants.LOCAL_FILE_PATH_2;
// % is used to trigger url encoding.
String filePath = prefix + "/foo%_foo%/" + EnvConstants.LOCAL_FILE_PATH_2;
WriteObjectSpec writeObjectSpec = new WriteObjectSpec(
EnvConstants.BUCKET_AT_REGION_1 /* bucketName*/,
filePath /* filePath */,
Expand All @@ -308,8 +309,18 @@ void listNextBatchOfVersions() throws IOException {
clientWithRegion1.putObject(writeObjectSpec);
}
// set max result of list request to 2
List<S3VersionSummary> summaries = clientWithRegion1.listVersions(EnvConstants.BUCKET_AT_REGION_1, prefix + '/' + EnvConstants.LOCAL_FILE_PATH_2, true /* useUrlEncoding */, /* maxKey */ 2);
List<S3VersionSummary> summaries = clientWithRegion1.listVersions(EnvConstants.BUCKET_AT_REGION_1, filePath, true /* useUrlEncoding */, /* maxKey */ 2);
List<S3VersionSummary> summaries2 = clientWithRegion1.listVersions(EnvConstants.BUCKET_AT_REGION_1, filePath, false /* useUrlEncoding */, /* maxKey */ 2);
Assertions.assertEquals(numVersions, summaries.size());
Assertions.assertEquals(numVersions, summaries2.size());
for (int i = 0; i < numVersions; i++) {
S3VersionSummary v1 = summaries.get(i);
S3VersionSummary v2 = summaries2.get(i);
Assertions.assertEquals(v1.getKey(), v2.getKey());
Assertions.assertEquals(v1.getVersionId(), v2.getVersionId());
Assertions.assertEquals(v1.getETag(), v2.getETag());
Assertions.assertEquals(v1.getSize(), v2.getSize());
}
}
@Test
void deleteObject() throws IOException {
Expand Down

0 comments on commit 32c76a8

Please sign in to comment.