Skip to content

Commit

Permalink
330292 - request.getParts() returns only one part when the name is th…
Browse files Browse the repository at this point in the history
…e same

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/branches/jetty-8@2511 7e9141cc-0065-0410-87d8-b60c137991c4
  • Loading branch information
Jan Bartel committed Nov 16, 2010
1 parent a87ae17 commit 0c11552
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
1 change: 1 addition & 0 deletions VERSION.txt
Expand Up @@ -9,6 +9,7 @@ jetty-8.0.0.M2-SNAPSHOT
+ 328008 Handle update to Servlet Spec 3 Section 8.2.3.h.ii
+ 330188 Reject web-fragment.xml with same <name> as another already loaded one
+ 330208 Support new wording on servlet-mapping and filter-mapping merging from servlet3.0a
+ 330292 request.getParts() returns only one part when the name is the same
+ Update to jetty-7.2.1.v20101111

jetty-7.2.1.v20101111 11 November 2010
Expand Down
Expand Up @@ -27,8 +27,10 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

Expand All @@ -49,8 +51,7 @@ public class MultiPartInputStream
protected InputStream _in;
protected MultipartConfigElement _config;
protected String _contentType;
protected MultiMap _map;
protected Map<String, Part> _parts;
protected MultiMap<String> _parts;
protected File _tmpDir;
protected File _contextTmpDir;

Expand Down Expand Up @@ -304,23 +305,22 @@ public Collection<Part> getParts()
throws IOException, ServletException
{
parse();
return _parts.values();
Collection<Object> values = _parts.values();
List<Part> parts = new ArrayList<Part>();
for (Object o: values)
{
List<Part> asList = LazyList.getList(o, false);
parts.addAll(asList);
}
return parts;
}


public Part getPart(String name)
throws IOException, ServletException
{
parse();
return _parts.get(name);
}


public MultiMap getMap ()
throws IOException, ServletException
{
parse();
return _map;
return (Part)_parts.getValue(name, 0);
}


Expand All @@ -333,7 +333,7 @@ protected void parse ()

//initialize
long total = 0; //keep running total of size of bytes read from input and throw an exception if exceeds MultipartConfigElement._maxRequestSize
_parts = new HashMap<String, Part>();
_parts = new MultiMap<String>();

//if its not a multipart request, don't parse it
if (_contentType == null || !_contentType.startsWith("multipart/form-data"))
Expand Down Expand Up @@ -480,7 +480,7 @@ public int read() throws IOException
MultiPart part = new MultiPart(name, filename);
part.setHeaders(headers);
part.setContentType(contentType);
_parts.put(name, part);
_parts.add(name, part);

part.open();

Expand Down
Expand Up @@ -56,7 +56,7 @@ public void testNonMultiPartRequest()
"Content-type: text/plain",
config,
new File(_dirname));
assertTrue(mpis.getParts().isEmpty());
assertTrue(mpis.getParts().isEmpty());
}

public void testNoLimits()
Expand Down Expand Up @@ -153,4 +153,35 @@ public void testMulti ()
assertTrue(f.exists());
}

public void testMultiSameNames ()
throws Exception
{
String sameNames = "--AaB03x\r\n"+
"content-disposition: form-data; name=\"stuff\"; filename=\"stuff1.txt\"\r\n"+
"Content-Type: text/plain\r\n"+
"\r\n"+
"00000\r\n"+
"--AaB03x\r\n"+
"content-disposition: form-data; name=\"stuff\"; filename=\"stuff2.txt\"\r\n"+
"Content-Type: text/plain\r\n"+
"\r\n"+
"000000000000000000000000000000000000000000000000000\r\n"+
"--AaB03x--\r\n";

MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
MultiPartInputStream mpis = new MultiPartInputStream(new ByteArrayInputStream(sameNames.getBytes()),
_contentType,
config,
new File(_dirname));

Collection<Part> parts = mpis.getParts();
assertEquals(2, parts.size());
for (Part p:parts)
assertEquals("stuff", p.getName());

//if they all have the name name, then only retrieve the first one
Part p = mpis.getPart("stuff");
assertNotNull(p);
assertEquals(5, p.getSize());
}
}

0 comments on commit 0c11552

Please sign in to comment.