1818
1919import static org .junit .Assert .*;
2020
21+ import java .net .URLEncoder ;
2122import java .util .ArrayList ;
2223import java .util .Arrays ;
2324import java .util .List ;
3132
3233import org .springframework .mock .web .test .MockHttpServletRequest ;
3334import org .springframework .mock .web .test .MockHttpServletResponse ;
34- import org .springframework .util .MultiValueMap ;
3535import org .springframework .web .servlet .FlashMap ;
3636import org .springframework .web .util .WebUtils ;
3737
@@ -113,19 +113,19 @@ public void retrieveAndUpdateMatchByParams() {
113113
114114 this .flashMapManager .setFlashMaps (Arrays .asList (flashMap ));
115115
116- this .request .setParameter ("number" , ( String ) null );
116+ this .request .setQueryString ("number=" );
117117 FlashMap inputFlashMap = this .flashMapManager .retrieveAndUpdate (this .request , this .response );
118118
119119 assertNull (inputFlashMap );
120120 assertEquals ("FlashMap should not have been removed" , 1 , this .flashMapManager .getFlashMaps ().size ());
121121
122- this .request .setParameter ("number" , " two" );
122+ this .request .setQueryString ("number= two" );
123123 inputFlashMap = this .flashMapManager .retrieveAndUpdate (this .request , this .response );
124124
125125 assertNull (inputFlashMap );
126126 assertEquals ("FlashMap should not have been removed" , 1 , this .flashMapManager .getFlashMaps ().size ());
127127
128- this .request .setParameter ("number" , " one" );
128+ this .request .setQueryString ("number= one" );
129129 inputFlashMap = this .flashMapManager .retrieveAndUpdate (this .request , this .response );
130130
131131 assertEquals (flashMap , inputFlashMap );
@@ -143,13 +143,13 @@ public void retrieveAndUpdateMatchWithMultiValueParam() {
143143
144144 this .flashMapManager .setFlashMaps (Arrays .asList (flashMap ));
145145
146- this .request .setParameter ("id" , " 1" );
146+ this .request .setQueryString ("id= 1" );
147147 FlashMap inputFlashMap = this .flashMapManager .retrieveAndUpdate (this .request , this .response );
148148
149149 assertNull (inputFlashMap );
150150 assertEquals ("FlashMap should not have been removed" , 1 , this .flashMapManager .getFlashMaps ().size ());
151151
152- this .request .addParameter ("id" , " 2" );
152+ this .request .setQueryString ("id=1&id= 2" );
153153 inputFlashMap = this .flashMapManager .retrieveAndUpdate (this .request , this .response );
154154
155155 assertEquals (flashMap , inputFlashMap );
@@ -268,20 +268,54 @@ public void saveOutputFlashMapNormalizeTargetPath() throws InterruptedException
268268
269269 @ Test
270270 public void saveOutputFlashMapDecodeParameters () throws Exception {
271+
272+ FlashMap flashMap = new FlashMap ();
273+ flashMap .put ("key" , "value" );
274+ flashMap .setTargetRequestPath ("/path" );
275+ flashMap .addTargetRequestParam ("param" , "%D0%90%D0%90" );
276+ flashMap .addTargetRequestParam ("param" , "%D0%91%D0%91" );
277+ flashMap .addTargetRequestParam ("param" , "%D0%92%D0%92" );
278+ flashMap .addTargetRequestParam ("%3A%2F%3F%23%5B%5D%40" , "value" );
279+
271280 this .request .setCharacterEncoding ("UTF-8" );
281+ this .flashMapManager .saveOutputFlashMap (flashMap , this .request , this .response );
282+
283+ MockHttpServletRequest requestAfterRedirect = new MockHttpServletRequest ("GET" , "/path" );
284+ requestAfterRedirect .setQueryString ("param=%D0%90%D0%90¶m=%D0%91%D0%91¶m=%D0%92%D0%92&%3A%2F%3F%23%5B%5D%40=value" );
285+ requestAfterRedirect .addParameter ("param" , "\u0410 \u0410 " );
286+ requestAfterRedirect .addParameter ("param" , "\u0411 \u0411 " );
287+ requestAfterRedirect .addParameter ("param" , "\u0412 \u0412 " );
288+ requestAfterRedirect .addParameter (":/?#[]@" , "value" );
289+
290+ flashMap = this .flashMapManager .retrieveAndUpdate (requestAfterRedirect , new MockHttpServletResponse ());
291+ assertNotNull (flashMap );
292+ assertEquals (1 , flashMap .size ());
293+ assertEquals ("value" , flashMap .get ("key" ));
294+ }
295+
296+ // SPR-12569
297+
298+ @ Test
299+ public void flashAttributesWithQueryParamsWithSpace () throws Exception {
300+
301+ String encodedValue = URLEncoder .encode ("1 2" , "UTF-8" );
272302
273303 FlashMap flashMap = new FlashMap ();
274- flashMap .put ("anyKey" , "anyValue" );
304+ flashMap .put ("key" , "value" );
305+ flashMap .setTargetRequestPath ("/path" );
306+ flashMap .addTargetRequestParam ("param" , encodedValue );
275307
276- flashMap .addTargetRequestParam ("key" , "%D0%90%D0%90" );
277- flashMap .addTargetRequestParam ("key" , "%D0%91%D0%91" );
278- flashMap .addTargetRequestParam ("key" , "%D0%92%D0%92" );
279- flashMap .addTargetRequestParam ("%3A%2F%3F%23%5B%5D%40" , "value" );
308+ this .request .setCharacterEncoding ("UTF-8" );
280309 this .flashMapManager .saveOutputFlashMap (flashMap , this .request , this .response );
281310
282- MultiValueMap <String ,String > targetRequestParams = flashMap .getTargetRequestParams ();
283- assertEquals (Arrays .asList ("\u0410 \u0410 " , "\u0411 \u0411 " , "\u0412 \u0412 " ), targetRequestParams .get ("key" ));
284- assertEquals (Arrays .asList ("value" ), targetRequestParams .get (":/?#[]@" ));
311+ MockHttpServletRequest requestAfterRedirect = new MockHttpServletRequest ("GET" , "/path" );
312+ requestAfterRedirect .setQueryString ("param=" + encodedValue );
313+ requestAfterRedirect .addParameter ("param" , "1 2" );
314+
315+ flashMap = this .flashMapManager .retrieveAndUpdate (requestAfterRedirect , new MockHttpServletResponse ());
316+ assertNotNull (flashMap );
317+ assertEquals (1 , flashMap .size ());
318+ assertEquals ("value" , flashMap .get ("key" ));
285319 }
286320
287321
0 commit comments