File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
main/java/org/springframework/http
test/java/org/springframework/http Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -277,7 +277,7 @@ public static ContentDisposition parse(String contentDisposition) {
277
277
}
278
278
else if (attribute .equals ("filename*" ) ) {
279
279
filename = decodeHeaderFieldParam (value );
280
- charset = Charset .forName (value .substring (0 , value .indexOf ('\'' )));
280
+ charset = Charset .forName (value .substring (0 , value .indexOf ('\'' )). trim () );
281
281
Assert .isTrue (UTF_8 .equals (charset ) || ISO_8859_1 .equals (charset ),
282
282
"Charset should be UTF-8 or ISO-8859-1" );
283
283
}
@@ -371,7 +371,7 @@ private static String decodeHeaderFieldParam(String input) {
371
371
if (firstQuoteIndex == -1 || secondQuoteIndex == -1 ) {
372
372
return input ;
373
373
}
374
- Charset charset = Charset .forName (input .substring (0 , firstQuoteIndex ));
374
+ Charset charset = Charset .forName (input .substring (0 , firstQuoteIndex ). trim () );
375
375
Assert .isTrue (UTF_8 .equals (charset ) || ISO_8859_1 .equals (charset ),
376
376
"Charset should be UTF-8 or ISO-8859-1" );
377
377
byte [] value = input .substring (secondQuoteIndex + 1 , input .length ()).getBytes (charset );
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -71,6 +71,14 @@ public void parseAndIgnoreEmptyParts() {
71
71
.name ("foo" ).filename ("foo.txt" ).size (123L ).build (), disposition );
72
72
}
73
73
74
+ @ Test // gh-24112
75
+ public void parseEncodedFilenameWithPaddedCharset () {
76
+ ContentDisposition disposition = ContentDisposition
77
+ .parse ("attachment; filename*= UTF-8''some-file.zip" );
78
+ assertEquals (ContentDisposition .builder ("attachment" )
79
+ .filename ("some-file.zip" , StandardCharsets .UTF_8 ).build (), disposition );
80
+ }
81
+
74
82
@ Test
75
83
public void parseEncodedFilename () {
76
84
ContentDisposition disposition = ContentDisposition
You can’t perform that action at this time.
0 commit comments