Skip to content

Commit

Permalink
ContentDisposition trims charset in filename
Browse files Browse the repository at this point in the history
Closes gh-24112
  • Loading branch information
rstoyanchev committed Dec 10, 2019
1 parent f180bf7 commit c8bce96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -282,7 +282,7 @@ else if (attribute.equals("filename*") ) {
int idx1 = value.indexOf('\'');
int idx2 = value.indexOf('\'', idx1 + 1);
if (idx1 != -1 && idx2 != -1) {
charset = Charset.forName(value.substring(0, idx1));
charset = Charset.forName(value.substring(0, idx1).trim());
Assert.isTrue(UTF_8.equals(charset) || ISO_8859_1.equals(charset),
"Charset should be UTF-8 or ISO-8859-1");
filename = decodeFilename(value.substring(idx2 + 1), charset);
Expand Down
Expand Up @@ -70,6 +70,14 @@ public void parseEncodedFilename() {
.build());
}

@Test // gh-24112
public void parseEncodedFilenameWithPaddedCharset() {
assertThat(parse("attachment; filename*= UTF-8''some-file.zip"))
.isEqualTo(ContentDisposition.builder("attachment")
.filename("some-file.zip", StandardCharsets.UTF_8)
.build());
}

@Test
public void parseEncodedFilenameWithoutCharset() {
assertThat(parse("form-data; name=\"name\"; filename*=test.txt"))
Expand Down

0 comments on commit c8bce96

Please sign in to comment.