Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JCLOUDS-1632: GCP BlobStore fails to put a blob if blob name contains non ASCII characters #201

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public MultipartForm(String boundary, Iterable<? extends Part> content) {
if (!part.isRepeatable())
isRepeatable = false;
contentLength += part.getContentMetadata().getContentLength()
+ createHeaders(boundaryrn, part).length()
+ createHeaders(boundaryrn, part).getBytes().length
+ createRn().length();
}
contentLength += createFooter(boundary).length();
Expand Down
32 changes: 23 additions & 9 deletions core/src/test/java/org/jclouds/io/payloads/MultipartFormTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,31 @@ public class MultipartFormTest {
public void testSinglePart() throws IOException {

StringBuilder builder = new StringBuilder();
addData(boundary, "hello", builder);
addData(boundary, "file", "hello", builder);
builder.append("--").append(boundary).append("--").append("\r\n");
String expects = builder.toString();
assertEquals(expects.length(), 199);

MultipartForm multipartForm = new MultipartForm(boundary, newPart("hello"));
MultipartForm multipartForm = new MultipartForm(boundary, newPart("file", "hello"));

assertEquals(Strings2.toStringAndClose(multipartForm.openStream()), expects);
assertEquals(multipartForm.getContentMetadata().getContentLength(), Long.valueOf(199));
}

public void testLengthIsCorrectPerUTF8() throws IOException {

StringBuilder builder = new StringBuilder();
addData(boundary, "unic₪de", "hello", builder);
builder.append("--").append(boundary).append("--").append("\r\n");
String expects = builder.toString();
assertEquals(expects.getBytes().length, 204);

MultipartForm multipartForm = new MultipartForm(boundary, newPart("unic₪de", "hello"));

assertEquals(Strings2.toStringAndClose(multipartForm.openStream()), expects);
assertEquals(multipartForm.getContentMetadata().getContentLength(), Long.valueOf(204));
}

public static class MockFilePayload extends FilePayload {

private final StringPayload realPayload;
Expand Down Expand Up @@ -81,14 +95,14 @@ public boolean isRepeatable() {
}
}

private Part newPart(String data) {
return Part.create("file", new MockFilePayload(data),
private Part newPart(String name, String data) {
return Part.create(name, new MockFilePayload(data),
new PartOptions().contentType(PLAIN_TEXT_UTF_8.withoutParameters().toString()));
}

private void addData(String boundary, String data, StringBuilder builder) {
private void addData(String boundary, String name, String data, StringBuilder builder) {
builder.append("--").append(boundary).append("\r\n");
builder.append("Content-Disposition").append(": ").append("form-data; name=\"file\"; filename=\"testfile.txt\"")
builder.append("Content-Disposition").append(": ").append("form-data; name=\"").append(name).append("\"; filename=\"testfile.txt\"")
.append("\r\n");
builder.append("Content-Type").append(": ").append("text/plain").append("\r\n");
builder.append("\r\n");
Expand All @@ -98,15 +112,15 @@ private void addData(String boundary, String data, StringBuilder builder) {
public void testMultipleParts() throws IOException {

StringBuilder builder = new StringBuilder();
addData(boundary, "hello", builder);
addData(boundary, "goodbye", builder);
addData(boundary, "file", "hello", builder);
addData(boundary, "file", "goodbye", builder);

builder.append("--").append(boundary).append("--").append("\r\n");
String expects = builder.toString();

assertEquals(expects.length(), 352);

MultipartForm multipartForm = new MultipartForm(boundary, newPart("hello"), newPart("goodbye"));
MultipartForm multipartForm = new MultipartForm(boundary, newPart("file", "hello"), newPart("file", "goodbye"));

assertEquals(Strings2.toStringAndClose(multipartForm.openStream()), expects);

Expand Down
Loading