Skip to content

Commit a3161dc

Browse files
committed
Merge branch '5.1.x'
2 parents 575027a + db8be50 commit a3161dc

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -41,6 +41,7 @@
4141
*
4242
* @author Rossen Stoyanchev
4343
* @author Juergen Hoeller
44+
* @author Sam Brannen
4445
* @since 3.1.1
4546
*/
4647
public abstract class AbstractFlashMapManager implements FlashMapManager {
@@ -219,7 +220,7 @@ public final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest reque
219220

220221
@Nullable
221222
private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) {
222-
if (path != null) {
223+
if (path != null && !path.isEmpty()) {
223224
path = getUrlPathHelper().decodeRequestString(request, path);
224225
if (path.charAt(0) != '/') {
225226
String requestUri = getUrlPathHelper().getRequestUri(request);

spring-webmvc/src/test/java/org/springframework/web/servlet/support/FlashMapManagerTests.java

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import javax.servlet.http.HttpServletResponse;
2727

2828
import org.assertj.core.api.ObjectAssert;
29-
import org.junit.Before;
3029
import org.junit.Test;
3130

3231
import org.springframework.mock.web.test.MockHttpServletRequest;
@@ -36,27 +35,19 @@
3635

3736
import static org.assertj.core.api.Assertions.assertThat;
3837

39-
4038
/**
4139
* Test fixture for testing {@link AbstractFlashMapManager} methods.
4240
*
4341
* @author Rossen Stoyanchev
42+
* @author Sam Brannen
4443
*/
4544
public class FlashMapManagerTests {
4645

47-
private TestFlashMapManager flashMapManager;
48-
49-
private MockHttpServletRequest request;
46+
private final TestFlashMapManager flashMapManager = new TestFlashMapManager();
5047

51-
private MockHttpServletResponse response;
48+
private final MockHttpServletRequest request = new MockHttpServletRequest();
5249

53-
54-
@Before
55-
public void setup() {
56-
this.flashMapManager = new TestFlashMapManager();
57-
this.request = new MockHttpServletRequest();
58-
this.response = new MockHttpServletResponse();
59-
}
50+
private final MockHttpServletResponse response = new MockHttpServletResponse();
6051

6152

6253
@Test
@@ -73,9 +64,7 @@ public void retrieveAndUpdateMatchByPath() {
7364
assertThatFlashMap(inputFlashMap).isEqualTo(flashMap);
7465
}
7566

76-
// SPR-8779
77-
78-
@Test
67+
@Test // SPR-8779
7968
public void retrieveAndUpdateMatchByOriginatingPath() {
8069
FlashMap flashMap = new FlashMap();
8170
flashMap.put("key", "value");
@@ -133,9 +122,7 @@ public void retrieveAndUpdateMatchByParams() {
133122
assertThat(this.flashMapManager.getFlashMaps().size()).as("Input FlashMap should have been removed").isEqualTo(0);
134123
}
135124

136-
// SPR-8798
137-
138-
@Test
125+
@Test // SPR-8798
139126
public void retrieveAndUpdateMatchWithMultiValueParam() {
140127
FlashMap flashMap = new FlashMap();
141128
flashMap.put("name", "value");
@@ -180,7 +167,7 @@ public void retrieveAndUpdateSortMultipleMatches() {
180167
}
181168

182169
@Test
183-
public void retrieveAndUpdateRemoveExpired() throws InterruptedException {
170+
public void retrieveAndUpdateRemoveExpired() {
184171
List<FlashMap> flashMaps = new ArrayList<>();
185172
for (int i = 0; i < 5; i++) {
186173
FlashMap expiredFlashMap = new FlashMap();
@@ -194,7 +181,7 @@ public void retrieveAndUpdateRemoveExpired() throws InterruptedException {
194181
}
195182

196183
@Test
197-
public void saveOutputFlashMapEmpty() throws InterruptedException {
184+
public void saveOutputFlashMapEmpty() {
198185
FlashMap flashMap = new FlashMap();
199186

200187
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
@@ -204,7 +191,7 @@ public void saveOutputFlashMapEmpty() throws InterruptedException {
204191
}
205192

206193
@Test
207-
public void saveOutputFlashMap() throws InterruptedException {
194+
public void saveOutputFlashMap() {
208195
FlashMap flashMap = new FlashMap();
209196
flashMap.put("name", "value");
210197

@@ -218,7 +205,7 @@ public void saveOutputFlashMap() throws InterruptedException {
218205
}
219206

220207
@Test
221-
public void saveOutputFlashMapDecodeTargetPath() throws InterruptedException {
208+
public void saveOutputFlashMapDecodeTargetPath() {
222209
FlashMap flashMap = new FlashMap();
223210
flashMap.put("key", "value");
224211

@@ -229,7 +216,7 @@ public void saveOutputFlashMapDecodeTargetPath() throws InterruptedException {
229216
}
230217

231218
@Test
232-
public void saveOutputFlashMapNormalizeTargetPath() throws InterruptedException {
219+
public void saveOutputFlashMapNormalizeTargetPath() {
233220
FlashMap flashMap = new FlashMap();
234221
flashMap.put("key", "value");
235222

@@ -264,11 +251,19 @@ public void saveOutputFlashMapNormalizeTargetPath() throws InterruptedException
264251
assertThat(flashMap.getTargetRequestPath()).isEqualTo("/once/only");
265252
}
266253

267-
// SPR-9657, SPR-11504
254+
@Test // gh-23240
255+
public void saveOutputFlashMapAndNormalizeEmptyTargetPath() {
256+
FlashMap flashMap = new FlashMap();
257+
flashMap.put("key", "value");
268258

269-
@Test
270-
public void saveOutputFlashMapDecodeParameters() throws Exception {
259+
flashMap.setTargetRequestPath("");
260+
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
261+
262+
assertThat(flashMap.getTargetRequestPath()).isEqualTo("");
263+
}
271264

265+
@Test // SPR-9657, SPR-11504
266+
public void saveOutputFlashMapDecodeParameters() throws Exception {
272267
FlashMap flashMap = new FlashMap();
273268
flashMap.put("key", "value");
274269
flashMap.setTargetRequestPath("/path");
@@ -294,11 +289,8 @@ public void saveOutputFlashMapDecodeParameters() throws Exception {
294289
assertThat(flashMap.get("key")).isEqualTo("value");
295290
}
296291

297-
// SPR-12569
298-
299-
@Test
292+
@Test // SPR-12569
300293
public void flashAttributesWithQueryParamsWithSpace() throws Exception {
301-
302294
String encodedValue = URLEncoder.encode("1 2", "UTF-8");
303295

304296
FlashMap flashMap = new FlashMap();

0 commit comments

Comments
 (0)