Skip to content
Closed
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 @@ -172,7 +172,7 @@ public String toString() {
sb.append(this.type);
}
if (this.name != null) {
sb.append("; name=\"").append(this.name).append('\"');
sb.append("; name=\"").append(encodeQuotedPairs(this.name)).append('\"');
}
if (this.filename != null) {
if (this.charset == null || StandardCharsets.US_ASCII.equals(this.charset)) {
Expand Down Expand Up @@ -253,7 +253,7 @@ public static ContentDisposition parse(String contentDisposition) {
part.substring(eqIndex + 2, part.length() - 1) :
part.substring(eqIndex + 1));
if (attribute.equals("name") ) {
name = value;
name = (value.indexOf('\\') != -1 ? decodeQuotedPairs(value) : value);
}
else if (attribute.equals("filename*") ) {
int idx1 = value.indexOf('\'');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,17 @@ void formatWithEncodedFilenameUsingInvalidCharset() {
.build()
.toString());
}

@Test
void formatAndParseWithNameWithQuotes() {
ContentDisposition cd = ContentDisposition.formData()
.name("foo\"bar\\baz")
.build();
assertThat(cd.toString()).isEqualTo("form-data; name=\"foo\\\"bar\\\\baz\"");

ContentDisposition parsed = ContentDisposition.parse("form-data; name=\"foo\\\"bar\\\\baz\"");
assertThat(parsed.getName()).isEqualTo("foo\"bar\\baz");
}
}

}