11/*
2- * Copyright 2002-2020 the original author or authors.
2+ * Copyright 2002-2021 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1818
1919import java .net .MalformedURLException ;
2020import java .net .URL ;
21+ import java .nio .charset .Charset ;
2122import java .nio .charset .StandardCharsets ;
2223import java .util .Arrays ;
2324import java .util .Collections ;
@@ -423,16 +424,15 @@ public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithMult
423424 }
424425
425426 @ Test // gh-24926
426- public void buildRequestParameterMapViaWebRequestDotSetFileToUploadAsParameter () throws Exception {
427-
427+ public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithFileToUploadAsParameter () throws Exception {
428428 webRequest .setRequestParameters (Collections .singletonList (
429429 new KeyDataPair ("key" ,
430430 new ClassPathResource ("org/springframework/test/web/htmlunit/test.txt" ).getFile (),
431431 "test.txt" , MimeType .TEXT_PLAIN , StandardCharsets .UTF_8 )));
432432
433433 MockHttpServletRequest actualRequest = requestBuilder .buildRequest (servletContext );
434434
435- assertThat (actualRequest .getParts (). size ()). isEqualTo (1 );
435+ assertThat (actualRequest .getParts ()). hasSize (1 );
436436 Part part = actualRequest .getPart ("key" );
437437 assertThat (part ).isNotNull ();
438438 assertThat (part .getName ()).isEqualTo ("key" );
@@ -441,6 +441,21 @@ public void buildRequestParameterMapViaWebRequestDotSetFileToUploadAsParameter()
441441 assertThat (part .getContentType ()).isEqualTo (MimeType .TEXT_PLAIN );
442442 }
443443
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+
444459 @ Test
445460 public void buildRequestParameterMapFromSingleQueryParam () throws Exception {
446461 webRequest .setUrl (new URL ("https://example.com/example/?name=value" ));
0 commit comments