Spring Framework
  1. Spring Framework
  2. SPR-9016

Provide property in RedirectView to disable treating the redirect URL as a URI template

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 3.1 GA
    • Fix Version/s: 3.1.1
    • Component/s: Web
    • Labels:
    • Last commented by a User:
      true

      Description

      Previously in Spring 3.0.6, it was entirely valid to return a redirect view with any arbitrary data in the anchor:

      Map<String, String> pojo = new HashMap<String, String>();
      pojo.put("one", "abc");
      String json = (new ObjectMapper()).writeValueAsString(pojo);
      return new RedirectView("/test#" + json, true);

      It seems like Spring 3.1GA attempts to replace '

      {' ABC '}

      ' with the corresponding variable in the model. However, it's perfectly valid for the anchor to json, which wouldn't work, or be expected.

      I don't see any option on the RedirectView to disable applying Uri Template Variables, or it should ignore everything after the '#', or both.

        Activity

        Hide
        Andrew Muraco added a comment -

        I know that Spring 3.x is significantly different from spring 1.2, but I found this relevant bug report asking for this feature: SPR-799

        Show
        Andrew Muraco added a comment - I know that Spring 3.x is significantly different from spring 1.2, but I found this relevant bug report asking for this feature: SPR-799
        Hide
        Rossen Stoyanchev added a comment - - edited

        I think what you're asking is a little different from SPR-799. Your question applies to any part of the URL. In other words the redirect view string is treated as a URI template and that doesn't stop at the "#". If you need to include such characters, create a placeholder and add the variable to the model.

        String json = ...
        model.addAttribute("anchor", json);
        return new RedirectView("/test#{anchor}", true);
        
        Show
        Rossen Stoyanchev added a comment - - edited I think what you're asking is a little different from SPR-799 . Your question applies to any part of the URL. In other words the redirect view string is treated as a URI template and that doesn't stop at the "#". If you need to include such characters, create a placeholder and add the variable to the model. String json = ... model.addAttribute( "anchor" , json); return new RedirectView( "/test#{anchor}" , true );
        Hide
        Andrew Muraco added a comment - - edited

        The is replaced with the escaped json. The anchor doesn't need to be escaped, I don't see a way to turn this off.

        I get

        /context/test#%7B%22id%22:null,....
        

        rather then

        /context/test#{id:null,....
        
        Show
        Andrew Muraco added a comment - - edited The is replaced with the escaped json. The anchor doesn't need to be escaped, I don't see a way to turn this off. I get /context/test#%7B%22id%22: null ,.... rather then /context/test#{id: null ,....
        Hide
        Rossen Stoyanchev added a comment -

        Ah, that's right. Expanded URI variable values are encoded as well much like query parameter values appended to the URL are. I guess we should provide a property to turn off applying URI template variables.

        Show
        Rossen Stoyanchev added a comment - Ah, that's right. Expanded URI variable values are encoded as well much like query parameter values appended to the URL are. I guess we should provide a property to turn off applying URI template variables.
        Hide
        Rossen Stoyanchev added a comment -

        I've modified the title to the better reflect the intended change (was "RedirectView does not ignore anchor when applying template variables with no way to turn it off").

        Show
        Rossen Stoyanchev added a comment - I've modified the title to the better reflect the intended change (was "RedirectView does not ignore anchor when applying template variables with no way to turn it off").
        Hide
        Andrew Muraco added a comment -

        Sounds like that will handle the situation I have nicely, thanks, I look forward to seeing it.

        Show
        Andrew Muraco added a comment - Sounds like that will handle the situation I have nicely, thanks, I look forward to seeing it.

          People

          • Assignee:
            Rossen Stoyanchev
            Reporter:
            Andrew Muraco
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 13 weeks, 5 days ago