Skip to content

Commit

Permalink
#339 - Content-Disposition is missing UTF-8 encoding marking
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Feb 3, 2025
1 parent 918de84 commit ef171e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 6 additions & 4 deletions aws-s3/src/main/java/com/formkiq/aws/s3/PresignGetUrlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ public PresignGetUrlConfig contentDisposition(final String contentDispositionStr
* @return {@link PresignGetUrlConfig}
*/
public PresignGetUrlConfig contentDispositionByPath(final String path, final boolean inline) {
String s = inline ? "inline" : "attachment";
String encodedPath = URLEncoder.encode(path, StandardCharsets.UTF_8);
this.contentDisposition =
path != null ? String.format("%s; filename=\"%s\"", s, encodedPath) : null;

if (path != null) {
String s = inline ? "inline" : "attachment";
String encodedPath = URLEncoder.encode(path, StandardCharsets.UTF_8).replaceAll("\\+", " ");
this.contentDisposition = String.format("%s; filename*=UTF-8''%s", s, encodedPath);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void testHandleGetDocumentContent01() throws Exception {
this.documentService.saveDocumentFormat(siteId, format);
}

String filename = "file_" + UUID.randomUUID() + ".pdf";
String filename = "file " + UUID.randomUUID() + ".pdf";
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, new Date(), userId);
item.setPath("/somepath/" + filename);
if ("text/plain".equals(contentType)) {
Expand All @@ -135,7 +135,7 @@ public void testHandleGetDocumentContent01() throws Exception {
assertNotNull(resp.getUrl());

URI uri = new URI(resp.getUrl());
assertTrue(uri.getQuery().contains("filename=\"" + filename + "\""));
assertTrue(uri.getQuery().contains("filename*=UTF-8''" + filename));

assertTrue(resp.getUrl().contains("X-Amz-Algorithm=AWS4-HMAC-SHA256"));
assertTrue(resp.getUrl().contains("X-Amz-Expires=172800"));
Expand Down Expand Up @@ -416,8 +416,7 @@ public void testHandleGetDocumentContent09() throws Exception {
assertNotNull(resp.getUrl());

URI uri = new URI(resp.getUrl());
assertTrue(uri.getQuery().contains("filename=\"" + filename + "\""));

assertTrue(uri.getQuery().contains("filename*=UTF-8''" + filename));
assertTrue(resp.getUrl().contains("X-Amz-Algorithm=AWS4-HMAC-SHA256"));
assertTrue(resp.getUrl().contains("X-Amz-Expires=172800"));
assertTrue(resp.getUrl().contains(AWS_REGION.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ void testPublish02() throws ApiException {
// then
assertEquals(ApiResponseStatus.SC_OK.getStatusCode(), response.getStatusCode());

assertEquals("attachment; filename=\"" + path + "\"",
assertEquals("attachment; filename*=UTF-8''" + path,
String.join(",", response.getHeaders().get("content-disposition")));
assertEquals("text/plain", String.join(",", response.getHeaders().get("content-type")));

Expand Down

0 comments on commit ef171e3

Please sign in to comment.