mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 18:48:00 -05:00
fix(s3): preserve literal question marks in copy source keys (#1924)
CopyObject and UploadPartCopy decoded the entire x-amz-copy-source header before splitting bucket, key, and query. A key containing a literal '?' (sent as %3F or raw) was then truncated at the first '?', so the copy resolved the wrong key and returned NoSuchKey. Split bucket/key/query on the raw header and decode each component separately. A trailing '?...' is only treated as a query string when it contains versionId=; otherwise the '?' is kept as part of the key. The same parsing is used by both CopyObject and UploadPartCopy. Adds a regression test covering encoded (%3F) and raw '?' copy sources. Closes #1713
This commit is contained in:
1 parent
c733e16523
commit
9308687f5a
2 files changed
+106
-37
No files matched your search
@@ -479,6 +479,67 @@ class S3IntegrationTest {
|
||||
given().delete("/" + bucket);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(120)
|
||||
void copyObjectWithQuestionMarkInSourceKeySucceeds() {
|
||||
String sourceBucket = "copy-question-source-bucket";
|
||||
String destBucket = "copy-question-dest-bucket";
|
||||
// The source key contains a literal '?'. Storing it requires a percent-encoded PUT path
|
||||
// (with urlEncodingEnabled(false)) so the '?' is not treated as the query-string delimiter.
|
||||
String rawSrcKey = "folder/file with question ?.txt";
|
||||
String encodedSrcKey = "folder/file%20with%20question%20%3F.txt";
|
||||
|
||||
given().put("/" + sourceBucket).then().statusCode(200);
|
||||
given().put("/" + destBucket).then().statusCode(200);
|
||||
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.contentType("text/plain")
|
||||
.body("copy test")
|
||||
.when()
|
||||
.put("/" + sourceBucket + "/" + encodedSrcKey)
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// AWS-style copy source: the key is URL-encoded, so the literal '?' arrives as %3F.
|
||||
given()
|
||||
.header("x-amz-copy-source", "/" + sourceBucket + "/" + encodedSrcKey)
|
||||
.when()
|
||||
.put("/" + destBucket + "/copied/encoded.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
|
||||
// Lenient case: a raw literal '?' in the copy source (no versionId query) is kept in the key.
|
||||
given()
|
||||
.header("x-amz-copy-source", "/" + sourceBucket + "/" + rawSrcKey)
|
||||
.when()
|
||||
.put("/" + destBucket + "/copied/raw.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("CopyObjectResult"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + destBucket + "/copied/encoded.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("copy test"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/" + destBucket + "/copied/raw.txt")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(equalTo("copy test"));
|
||||
|
||||
given().urlEncodingEnabled(false).delete("/" + sourceBucket + "/" + encodedSrcKey);
|
||||
given().delete("/" + destBucket + "/copied/encoded.txt");
|
||||
given().delete("/" + destBucket + "/copied/raw.txt");
|
||||
given().delete("/" + sourceBucket);
|
||||
given().delete("/" + destBucket);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void copyObjectWithMalformedEncodedSourceReturns400() {
|
||||
|
||||
Reference in new issue
Block a user