Skip to content

Commit

Permalink
WebRequest.getParameters(): switch order for multipart requests (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Aug 5, 2024
1 parent 24ca458 commit 0e375e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/htmlunit/WebRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,11 @@ public List<NameValuePair> getParameters() {
if (FormEncodingType.MULTIPART == getEncodingType()) {
final List<NameValuePair> allParameters = new ArrayList<>();

allParameters.addAll(HttpUtils.parseUrlQuery(getUrl().getQuery(), getCharset()));

// the servlet api ignores these parameters but to make spring happy we include them
allParameters.addAll(getRequestParameters());

allParameters.addAll(HttpUtils.parseUrlQuery(getUrl().getQuery(), getCharset()));
return normalize(allParameters);
}

Expand Down
36 changes: 18 additions & 18 deletions src/test/java/org/htmlunit/WebRequest2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,24 +361,6 @@ private static void bounce(final Writer writer,
final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
writer.write("Parameters: \n");

// different from the servlet api spring also uses the file upload information
try {
// if (ServletFileUpload.isMultipartContent(req)) {
// ignore the post request check
if (FileUploadBase.isMultipartContent(new ServletRequestContext(req))) {
final DiskFileItemFactory factory = new DiskFileItemFactory();

final ServletFileUpload upload = new ServletFileUpload(factory);
final List<FileItem> items = upload.parseRequest(req);
for (final FileItem fileItem : items) {
writer.write(" '" + fileItem.getFieldName() + "': '" + fileItem.getString() + "'\n");
}
}
}
catch (final FileUploadException e) {
throw new IOException(e);
}

// use only getParameterMap() here because we like to have the same behavior
for (final Map.Entry<String, String[]> entry : req.getParameterMap().entrySet()) {
if (entry.getValue() == null) {
Expand All @@ -402,6 +384,24 @@ else if (entry.getValue().length == 0) {
writer.write("]\n");
}
}

// different from the servlet api spring also uses the file upload information
try {
// if (ServletFileUpload.isMultipartContent(req)) {
// ignore the post request check
if (FileUploadBase.isMultipartContent(new ServletRequestContext(req))) {
final DiskFileItemFactory factory = new DiskFileItemFactory();

final ServletFileUpload upload = new ServletFileUpload(factory);
final List<FileItem> items = upload.parseRequest(req);
for (final FileItem fileItem : items) {
writer.write(" '" + fileItem.getFieldName() + "': '" + fileItem.getString() + "'\n");
}
}
}
catch (final FileUploadException e) {
throw new IOException(e);
}
}
}
}

0 comments on commit 0e375e3

Please sign in to comment.