-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
\n in form model when using Jetty 12 client and multipart/form-data #31361
Comments
This is likely down to Jetty as we don't parse ourselves but rather access request params and parts. Do those look okay if accessed directly through the HttpServletRequest? |
I get the same failure if I use the @PostMapping(path = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public OutputForm greetingSubmit(HttpServletRequest servletRequest, @ModelAttribute InputForm form) throws ServletException, IOException {
Map<String, String> parts = new HashMap<>();
for (Part part : servletRequest.getParts()) {
try (InputStream inputStream = part.getInputStream()) {
String content = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
parts.put(part.getName(), content);
}
}
return new OutputForm(parts.get("firstName"), parts.get("lastName"));
} |
Hm. It looks like it's related to the sender side. I have this code: 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.getStatusCode()).isEqualTo(HttpStatusCode.valueOf(200));
assertThat(result.getBody().firstName()).isEqualTo("first-name");
assertThat(result.getBody().lastName()).isEqualTo("last-name"); When the
|
Thanks for the further investigation. Part writing happens in FormHttpMessageConverter and is the same for any client, and has been in place for a very long time (hasn't changed recently). If the issue is reproducible with direct use of Jetty HttpClient, then it is for the Jetty issue tracker. It could be that some of the changes in jetty/jetty.project#9076 are related to this. |
I did some investigation of this, and—in short—still don't understand what's going on. I'm pretty sure that it is a Jetty 12 client-side bug, because of the reasons mentioned by @rstoyanchev (i.e. the I even went as far as to see what is exactly posted by your The only thing that I can think of is that it's off-by-one error, because the byte that precedes |
I fixed the issue, by buffering By looking at the dump from |
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:and i expect this test to pass:
This fails with Jetty 12, giving me this error message:
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.
jetty-form-submission.zip
The text was updated successfully, but these errors were encountered: