mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
Merge pull request #890 from aschweer/ds-2513-multipart-headers
[DS-2513] Improve multipart header parsing
This commit is contained in:
@@ -9,6 +9,7 @@ package org.dspace.app.xmlui.cocoon.servlet.multipart;
|
|||||||
|
|
||||||
import org.apache.cocoon.servlet.multipart.*;
|
import org.apache.cocoon.servlet.multipart.*;
|
||||||
import org.apache.cocoon.util.NullOutputStream;
|
import org.apache.cocoon.util.NullOutputStream;
|
||||||
|
import org.apache.commons.fileupload.ParameterParser;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -16,6 +17,7 @@ import javax.servlet.http.HttpSession;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -362,8 +364,11 @@ public class DSpaceMultipartParser {
|
|||||||
Hashtable headers = new Hashtable();
|
Hashtable headers = new Hashtable();
|
||||||
String hdrline = readln(in);
|
String hdrline = readln(in);
|
||||||
|
|
||||||
|
ParameterParser parser = new ParameterParser();
|
||||||
|
|
||||||
while (!"".equals(hdrline)) {
|
while (!"".equals(hdrline)) {
|
||||||
String name = StringUtils.substringBefore(hdrline, ": ").toLowerCase();
|
String name = StringUtils.substringBefore(hdrline, ": ").toLowerCase();
|
||||||
|
|
||||||
String value;
|
String value;
|
||||||
if(hdrline.contains(";")){
|
if(hdrline.contains(";")){
|
||||||
value = StringUtils.substringBetween(hdrline, ": ", "; ");
|
value = StringUtils.substringBetween(hdrline, ": ", "; ");
|
||||||
@@ -374,22 +379,13 @@ public class DSpaceMultipartParser {
|
|||||||
headers.put(name, value);
|
headers.put(name, value);
|
||||||
|
|
||||||
hdrline = StringUtils.substringAfter(hdrline, ";");
|
hdrline = StringUtils.substringAfter(hdrline, ";");
|
||||||
|
if (StringUtils.isNotBlank(hdrline)) {
|
||||||
// The extra tokenizer.hasMoreTokens() hdrline headers.put
|
Map parsed = parser.parse(hdrline, ';');
|
||||||
// handles the filename="" case IE6 submits for an empty
|
if (parsed.containsKey("filename") && parsed.get("filename") == null) {
|
||||||
// upload field.
|
parsed.put("filename", ""); // apparently, IE6 sometimes submits filename=""
|
||||||
while (0 < hdrline.length()) {
|
}
|
||||||
name = StringUtils.substringBetween(hdrline, " ", "=");
|
headers.putAll(parsed); // source out parsing of the rest of the header - it gets quite tricky with respecting quotes etc
|
||||||
if(hdrline.contains("; ")){
|
}
|
||||||
value = StringUtils.substringBetween(hdrline, "=\"", "\";");
|
|
||||||
hdrline = StringUtils.substringAfter(hdrline, ";");
|
|
||||||
}else{
|
|
||||||
value = StringUtils.substringBetween(hdrline, "=\"", "\"");
|
|
||||||
hdrline = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
headers.put(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
hdrline = readln(in);
|
hdrline = readln(in);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user