Browse Source

Support multiple base64 segments in Content-Disposition

See gh-28236
pull/28403/head
Alex Lei 3 years ago committed by Arjen Poutsma
parent
commit
195b622411
  1. 8
      spring-web/src/main/java/org/springframework/http/ContentDisposition.java
  2. 8
      spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java

8
spring-web/src/main/java/org/springframework/http/ContentDisposition.java

@ -377,7 +377,13 @@ public final class ContentDisposition { @@ -377,7 +377,13 @@ public final class ContentDisposition {
if (matcher.find()) {
charset = Charset.forName(matcher.group(1));
String encodedValue = matcher.group(2);
filename = new String(Base64.getDecoder().decode(encodedValue), charset);
StringBuilder sb = new StringBuilder(new String(Base64.getDecoder().decode(encodedValue), charset));
while (matcher.find()){
charset = Charset.forName(matcher.group(1));
encodedValue = matcher.group(2);
sb.append(new String(Base64.getDecoder().decode(encodedValue), charset));
}
filename = sb.toString();
}
else {
matcher = QUOTED_PRINTABLE_ENCODED_PATTERN.matcher(value);

8
spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java

@ -86,6 +86,14 @@ class ContentDispositionTests { @@ -86,6 +86,14 @@ class ContentDispositionTests {
assertThat(parse(input).getFilename()).isEqualTo("日本語.csv");
}
@Test
void parseBase64EncodedFilenameHasMoreSegments() {
/* https://datatracker.ietf.org/doc/html/rfc2047#section-2
* An 'encoded-word' may not be more than 75 characters long */
String input = "attachment; filename=\"=?utf-8?B?U3ByaW5n5qGG5p625Li65Z+65LqOSmF2YeeahOeOsOS7o+S8geS4muW6lA==?= =?utf-8?B?55So56iL5bqP5o+Q5L6b5LqG5YWo6Z2i55qE57yW56iL5ZKM6YWN572u5qih?= =?utf-8?B?5Z6LLnR4dA==?=\"";
assertThat(parse(input).getFilename()).isEqualTo("Spring框架为基于Java的现代企业应用程序提供了全面的编程和配置模型.txt");
}
@Test // gh-26463
void parseBase64EncodedShiftJISFilename() {
String input = "attachment; filename=\"=?SHIFT_JIS?B?k/qWe4zqLmNzdg==?=\"";

Loading…
Cancel
Save