-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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
Support empty file uploads with HtmlUnit and MockMvc #26799
Comments
Perhaps instead of ignoring it we should fall back to the default handling and add the parameter's name and value to the request (as if it were not a @rstoyanchev, thoughts? |
Yes, we will try to. It's actual not my nor my projects setup so I am acting more or less as a proxy. I am gently, well, pushing for it, but I am not into their timeline so I can't exactly say when to expect some results. |
This commit revises the fix submitted in 959e6d1 by ensuring that empty file input is converted to a MockPart with the supplied name, an empty filename, "application/octet-stream" as the content type, and empty content. This aligns with the behavior of Servlet containers, as tested with the interaction between Firefox and a standard Servlet running in a Jetty Servlet container. Closes spring-projectsgh-26799
Understood! Please note that I have slightly revised the fix in d79e33b. |
Prior to this commit, when using HtmlUnit with empty file input, MockMvc's HtmlUnitRequestBuilder would throw a NullPointerException when attempting to create a MockPart based on the null File. This commit ensures that empty file input is converted to a MockPart with a valid name but with a null filename, a null content type, and empty content. Closes spring-projectsgh-26799
This commit revises the fix submitted in 959e6d1 by ensuring that empty file input is converted to a MockPart with the supplied name, an empty filename, "application/octet-stream" as the content type, and empty content. This aligns with the behavior of Servlet containers, as tested with the interaction between Firefox and a standard Servlet running in a Jetty Servlet container. Closes spring-projectsgh-26799
Prior to this commit, when using HtmlUnit with empty file input, MockMvc's HtmlUnitRequestBuilder would throw a NullPointerException when attempting to create a MockPart based on the null File. This commit ensures that empty file input is converted to a MockPart with a valid name but with a null filename, a null content type, and empty content. Closes spring-projectsgh-26799
This commit revises the fix submitted in 959e6d1 by ensuring that empty file input is converted to a MockPart with the supplied name, an empty filename, "application/octet-stream" as the content type, and empty content. This aligns with the behavior of Servlet containers, as tested with the interaction between Firefox and a standard Servlet running in a Jetty Servlet container. Closes spring-projectsgh-26799
When one uses HtmlUnit as a Web Client for tests, the
HtmlUnitRequestBuilder
can't cope with empty file input fields. It just tries to access the field instance and throws aNullPointerException
.HtmlUnit produces an
KeyValuePair
with anull
file (so thefile
variable is explicitly set tonull
). However the current implementation in Spring doesn't cope well with that field beingnull
, which results in aNullPointerException
being thrown.I guess an empty file input field should just be ignored, so maybe the best way to deal with it would be something along the lines of:
because I don't think we should drop to the default handling of
request.addParameter(param.getName(), param.getValue());
a few lines later.For reference, I think the problem was introduced in this pull request (1 year)
where as HtmlUnit has this behavior probably longer (the last change on the line was 4 years before). Which is why I think it makes probably more sense to fix it here.
The text was updated successfully, but these errors were encountered: