@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2020 the original author or authors .
* Copyright 2002 - 2021 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -18,6 +18,7 @@ package org.springframework.test.web.servlet.htmlunit;
@@ -18,6 +18,7 @@ package org.springframework.test.web.servlet.htmlunit;
import java.net.MalformedURLException ;
import java.net.URL ;
import java.nio.charset.Charset ;
import java.nio.charset.StandardCharsets ;
import java.util.Arrays ;
import java.util.Collections ;
@ -423,8 +424,7 @@ public class HtmlUnitRequestBuilderTests {
@@ -423,8 +424,7 @@ public class HtmlUnitRequestBuilderTests {
}
@Test // gh-24926
public void buildRequestParameterMapViaWebRequestDotSetFileToUploadAsParameter ( ) throws Exception {
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithFileToUploadAsParameter ( ) throws Exception {
webRequest . setRequestParameters ( Collections . singletonList (
new KeyDataPair ( "key" ,
new ClassPathResource ( "org/springframework/test/web/htmlunit/test.txt" ) . getFile ( ) ,
@ -432,7 +432,7 @@ public class HtmlUnitRequestBuilderTests {
@@ -432,7 +432,7 @@ public class HtmlUnitRequestBuilderTests {
MockHttpServletRequest actualRequest = requestBuilder . buildRequest ( servletContext ) ;
assertThat ( actualRequest . getParts ( ) . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( actualRequest . getParts ( ) ) . hasSize ( 1 ) ;
Part part = actualRequest . getPart ( "key" ) ;
assertThat ( part ) . isNotNull ( ) ;
assertThat ( part . getName ( ) ) . isEqualTo ( "key" ) ;
@ -441,6 +441,21 @@ public class HtmlUnitRequestBuilderTests {
@@ -441,6 +441,21 @@ public class HtmlUnitRequestBuilderTests {
assertThat ( part . getContentType ( ) ) . isEqualTo ( MimeType . TEXT_PLAIN ) ;
}
@Test // gh-26799
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithNullFileToUploadAsParameter ( ) throws Exception {
webRequest . setRequestParameters ( Collections . singletonList ( new KeyDataPair ( "key" , null , null , null , ( Charset ) null ) ) ) ;
MockHttpServletRequest actualRequest = requestBuilder . buildRequest ( servletContext ) ;
assertThat ( actualRequest . getParts ( ) ) . hasSize ( 1 ) ;
Part part = actualRequest . getPart ( "key" ) ;
assertThat ( part ) . isNotNull ( ) ;
assertThat ( part . getName ( ) ) . isEqualTo ( "key" ) ;
assertThat ( IOUtils . toString ( part . getInputStream ( ) , StandardCharsets . UTF_8 ) ) . isEqualTo ( "" ) ;
assertThat ( part . getSubmittedFileName ( ) ) . isNull ( ) ;
assertThat ( part . getContentType ( ) ) . isNull ( ) ;
}
@Test
public void buildRequestParameterMapFromSingleQueryParam ( ) throws Exception {
webRequest . setUrl ( new URL ( "https://example.com/example/?name=value" ) ) ;