Closed
Description
Hello,
I'm using Jetty 12.0.1 and observe the control character \r
in my populated model attribute. With Jetty I have this controller:
@RestController
public class FormSubmissionController {
@PostMapping(path = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public OutputForm greetingSubmit(@ModelAttribute InputForm form) {
return new OutputForm(form.firstName, form.lastName);
}
public record InputForm(String firstName, String lastName) {
}
public record OutputForm(String firstName, String lastName) {
}
}
and i expect this test to pass:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class JettyFormSubmissionApplicationTests {
@Autowired
private TestRestTemplate testRestTemplate;
@Test
void test() {
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("firstName", "first-name");
formData.add("lastName", "last-name");
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE);
RequestEntity<?> requestEntity = new RequestEntity<>(formData, headers, HttpMethod.POST, URI.create("/"));
ResponseEntity<FormSubmissionController.OutputForm> result = this.testRestTemplate.exchange(requestEntity, FormSubmissionController.OutputForm.class);
assertThat(result.getBody().firstName()).isEqualTo("first-name");
assertThat(result.getBody().lastName()).isEqualTo("last-name");
}
}
This fails with Jetty 12, giving me this error message:
org.opentest4j.AssertionFailedError:
expected: "last-name"
but was: "
last-name"
With Jetty 11.0.15, it works.
I have prepared a small reproducer. You can switch back to Jetty 11 by editing the build.gradle, i've put some comments in.