Support empty target request path in FlashMap

Prior to this commit, if the user configured an empty path for the
targetRequestPath property of a FlashMap, the FlashMapManager threw a
StringIndexOutOfBoundsException when saving the output FlashMap for the
next request.

This commit fixes this by skipping the decoding and normalization of an
empty target request path. An empty target request path is therefore
effectively treated as the root path.

Fixes gh-23240
This commit is contained in:
Sam Brannen
2019-07-07 18:26:59 +02:00
parent d893cdaabb
commit 271885cdf4
2 changed files with 28 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -41,6 +41,7 @@ import org.springframework.web.util.UrlPathHelper;
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sam Brannen
* @since 3.1.1
*/
public abstract class AbstractFlashMapManager implements FlashMapManager {
@@ -228,7 +229,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
@Nullable
private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) {
if (path != null) {
if (path != null && !path.isEmpty()) {
path = getUrlPathHelper().decodeRequestString(request, path);
if (path.charAt(0) != '/') {
String requestUri = getUrlPathHelper().getRequestUri(request);