1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2021 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.
18
18
19
19
import java .net .MalformedURLException ;
20
20
import java .net .URL ;
21
+ import java .nio .charset .Charset ;
21
22
import java .nio .charset .StandardCharsets ;
22
23
import java .util .Arrays ;
23
24
import java .util .Collections ;
@@ -423,16 +424,15 @@ public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithMult
423
424
}
424
425
425
426
@ Test // gh-24926
426
- public void buildRequestParameterMapViaWebRequestDotSetFileToUploadAsParameter () throws Exception {
427
-
427
+ public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithFileToUploadAsParameter () throws Exception {
428
428
webRequest .setRequestParameters (Collections .singletonList (
429
429
new KeyDataPair ("key" ,
430
430
new ClassPathResource ("org/springframework/test/web/htmlunit/test.txt" ).getFile (),
431
431
"test.txt" , MimeType .TEXT_PLAIN , StandardCharsets .UTF_8 )));
432
432
433
433
MockHttpServletRequest actualRequest = requestBuilder .buildRequest (servletContext );
434
434
435
- assertThat (actualRequest .getParts (). size ()). isEqualTo (1 );
435
+ assertThat (actualRequest .getParts ()). hasSize (1 );
436
436
Part part = actualRequest .getPart ("key" );
437
437
assertThat (part ).isNotNull ();
438
438
assertThat (part .getName ()).isEqualTo ("key" );
@@ -441,6 +441,21 @@ public void buildRequestParameterMapViaWebRequestDotSetFileToUploadAsParameter()
441
441
assertThat (part .getContentType ()).isEqualTo (MimeType .TEXT_PLAIN );
442
442
}
443
443
444
+ @ Test // gh-26799
445
+ public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithNullFileToUploadAsParameter () throws Exception {
446
+ webRequest .setRequestParameters (Collections .singletonList (new KeyDataPair ("key" , null , null , null , (Charset ) null )));
447
+
448
+ MockHttpServletRequest actualRequest = requestBuilder .buildRequest (servletContext );
449
+
450
+ assertThat (actualRequest .getParts ()).hasSize (1 );
451
+ Part part = actualRequest .getPart ("key" );
452
+ assertThat (part ).isNotNull ();
453
+ assertThat (part .getName ()).isEqualTo ("key" );
454
+ assertThat (IOUtils .toString (part .getInputStream (), StandardCharsets .UTF_8 )).isEqualTo ("" );
455
+ assertThat (part .getSubmittedFileName ()).isNull ();
456
+ assertThat (part .getContentType ()).isNull ();
457
+ }
458
+
444
459
@ Test
445
460
public void buildRequestParameterMapFromSingleQueryParam () throws Exception {
446
461
webRequest .setUrl (new URL ("https://example.com/example/?name=value" ));
0 commit comments