@@ -149,27 +149,25 @@ void parseEncodedFilenameWithInvalidName() {
149
149
.isThrownBy (() -> parse ("form-data; name=\" name\" ; filename*=UTF-8''%A.txt" ));
150
150
}
151
151
152
- @ Test // gh-23077
153
- @ SuppressWarnings ("deprecation" )
154
- void parseWithEscapedQuote () {
155
- BiConsumer <String , String > tester = (description , filename ) ->
156
- assertThat (parse ("form-data; name=\" file\" ; filename=\" " + filename + "\" ; size=123" ))
157
- .as (description )
158
- .isEqualTo (ContentDisposition .formData ().name ("file" ).filename (filename ).size (123L ).build ());
159
-
160
- tester .accept ("Escaped quotes should be ignored" ,
161
- "\\ \" The Twilight Zone\\ \" .txt" );
162
-
163
- tester .accept ("Escaped quotes preceded by escaped backslashes should be ignored" ,
164
- "\\ \\ \\ \" The Twilight Zone\\ \\ \\ \" .txt" );
165
-
166
- tester .accept ("Escaped backslashes should not suppress quote" ,
167
- "The Twilight Zone \\ \\ " );
152
+ @ Test
153
+ void parseBackslash () {
154
+ String s = "form-data; name=\" foo\" ; filename=\" foo\\ \\ bar \\ \" baz\\ \" qux \\ \\ \\ \" quux.txt\" " ;
155
+ ContentDisposition cd = ContentDisposition .parse (
156
+ s );
157
+ assertThat (cd .getName ()).isEqualTo ("foo" );
158
+ assertThat (cd .getFilename ()).isEqualTo ("foo\\ bar \" baz\" qux \\ \" quux.txt" );
159
+ assertThat (cd .toString ()).isEqualTo (s );
160
+ }
168
161
169
- tester .accept ("Escaped backslashes should not suppress quote" ,
170
- "The Twilight Zone \\ \\ \\ \\ " );
162
+ @ Test
163
+ void parseBackslashInLastPosition () {
164
+ ContentDisposition cd = ContentDisposition .parse ("form-data; name=\" foo\" ; filename=\" bar\\ \" " );
165
+ assertThat (cd .getName ()).isEqualTo ("foo" );
166
+ assertThat (cd .getFilename ()).isEqualTo ("bar\\ " );
167
+ assertThat (cd .toString ()).isEqualTo ("form-data; name=\" foo\" ; filename=\" bar\\ \\ \" " );
171
168
}
172
169
170
+
173
171
@ Test
174
172
@ SuppressWarnings ("deprecation" )
175
173
void parseWithExtraSemicolons () {
@@ -281,26 +279,26 @@ void formatWithFilenameWithQuotes() {
281
279
};
282
280
283
281
String filename = "\" foo.txt" ;
284
- tester .accept (filename , "\\ " + filename );
282
+ tester .accept (filename , "\\ \" foo.txt" );
285
283
286
284
filename = "\\ \" foo.txt" ;
287
- tester .accept (filename , filename );
285
+ tester .accept (filename , " \\ \\ \\ \" foo.txt" );
288
286
289
287
filename = "\\ \\ \" foo.txt" ;
290
- tester .accept (filename , "\\ " + filename );
288
+ tester .accept (filename , "\\ \\ \\ \\ \\ \" foo.txt" );
291
289
292
290
filename = "\\ \\ \\ \" foo.txt" ;
293
- tester .accept (filename , filename );
291
+ tester .accept (filename , " \\ \\ \\ \\ \\ \\ \\ \" foo.txt" );
294
292
295
293
filename = "\\ \\ \\ \\ \" foo.txt" ;
296
- tester .accept (filename , "\\ " + filename );
294
+ tester .accept (filename , "\\ \\ \\ \\ \\ \\ \\ \\ \\ \" foo.txt" );
297
295
298
296
tester .accept ("\" \" foo.txt" , "\\ \" \\ \" foo.txt" );
299
297
tester .accept ("\" \" \" foo.txt" , "\\ \" \\ \" \\ \" foo.txt" );
300
298
301
- tester .accept ("foo.txt\\ " , "foo.txt" );
302
- tester .accept ("foo.txt\\ \\ " , "foo.txt\\ \\ " );
303
- tester .accept ("foo.txt\\ \\ \\ " , "foo.txt\\ \\ " );
299
+ tester .accept ("foo.txt\\ " , "foo.txt\\ \\ " );
300
+ tester .accept ("foo.txt\\ \\ " , "foo.txt\\ \\ \\ \\ " );
301
+ tester .accept ("foo.txt\\ \\ \\ " , "foo.txt\\ \\ \\ \\ \\ \\ " );
304
302
}
305
303
306
304
@ Test
@@ -313,4 +311,14 @@ void formatWithEncodedFilenameUsingInvalidCharset() {
313
311
.toString ());
314
312
}
315
313
314
+ @ Test
315
+ void parseFormatted () {
316
+ ContentDisposition cd = ContentDisposition .builder ("form-data" )
317
+ .name ("foo" )
318
+ .filename ("foo\\ bar \" baz\" qux \\ \" quux.txt" ).build ();
319
+ ContentDisposition parsed = ContentDisposition .parse (cd .toString ());
320
+ assertThat (parsed ).isEqualTo (cd );
321
+ assertThat (parsed .toString ()).isEqualTo (cd .toString ());
322
+ }
323
+
316
324
}
0 commit comments