Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-15753

MockMvc duplicates PUT Parameter value

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 5.0 RC2
    • Fix Version/s: 4.3.10, 5.0 RC3
    • Component/s: Test
    • Labels:
    • Last commented by a User:
      true

      Description

      When I run test against a Controller with @PutMapping and a parameter with custom type, say

      public class Data {
          private String d1;
          private String d2;
      }
      
      @PutMapping()
      public String test(Data d)
      

      and

      MockMvc.perform(put("/")
                                  .content("d1=a&d2=s")
                                  .contentType(MediaType.APPLICATION_FORM_URLENCODED))
      

      I'll get unexpected result that I got d1="a,a", d2="s,s".
      But a normal PUT request works fine.

      With some digging, I noticed that the first line of HttpPutFormContentFilter#getParameterValues(String)
      returns null when requested normally but return the values in form data under test environment(when the request is of type MockHttpServletRequest).

      I wrote a little spring boot project to demonstrate it. And there is some screenshot shows the difference between a real request and a mocked request.

        Attachments

        1. 1.png
          1.png
          67 kB
        2. 2.png
          2.png
          82 kB
        3. 3.png
          3.png
          68 kB
        4. 4.png
          4.png
          68 kB
        5. SpringBootTest.zip
          142 kB

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              librazy Liqueur Librazy
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

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