Skip to content

flash attributes not mapped from session to request scope when parameter value is url encoded [SPR-12986] #17577

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions