Description
Patrick Bucher opened SPR-12986 and commented
Here's my controller:
package com.getabstract.web;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@Controller
@RequestMapping("/mock")
public class MockController
{
@RequestMapping(value = "/input", method = RequestMethod.GET)
public String postInput(RedirectAttributes redirectAttributes)
{
redirectAttributes.addFlashAttribute("message", "some message");
redirectAttributes.addAttribute("mockParam", "this_is_a_test");
return "redirect:/mock/output";
}
@RequestMapping(value = "/output", method = RequestMethod.GET)
public String getOutput(@RequestParam String mockParam, Model model)
{
model.addAttribute("mockAttribute", "some mock text: " + mockParam);
return "mock/output";
}
}
And here's my JSP:
<jsp:directive.include file="/WEB-INF/views/common/taglib.jsp" />
<html>
<head></head>
<body>
<p>Message: ${message}</p>
</body>
</html>
When I run this code by calling /mock/input, the message "this_is_a_test" is outputted correctly on the JSP.
Message: some message
Now I change my message slightly, so that URL Encoding becomes necessary (replacing underscores with spaces):
redirectAttributes.addAttribute("mockParam", "this is a test");
Now I'm getting forwarded to mock/output?mockParam=this+is+a+test, URL encoding has taken place.
The flash attribute map is not mapped from the session to the request, because AbstractFlashMapManager.isFlashMapForRequest() returns false. This method compares URL encoded values with non-encoded values. There's no org.springframework.web.servlet.DispatcherServlet.INPUT_FLASH_MAP available in the request scope, but all the parameters are in the session scope's org.springframework.web.servlet.support.SessionFlashMapManager.FLASH_MAPS.
Affects: 3.2.2
Issue Links:
- Flash attributes not working with spaces in query parameters [SPR-12569] #17170 Flash attributes not working with spaces in query parameters ("duplicates")
- Unable to retrieve FlashMap when contains "+"(half-space) in the request parameters [SPR-11821] #16441 Unable to retrieve FlashMap when contains "+"(half-space) in the request parameters