This is an automated email from the ASF dual-hosted git repository.

dashorst pushed a commit to branch archive/wicket-1.1.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit 6b3dbac44fab86879f57f3a2b3b1c67763620d47
Author: Igor Vaynberg <[email protected]>
AuthorDate: Thu Mar 2 21:09:49 2006 +0000

    fixed nasty file upload bug
    
    
    git-svn-id: 
https://svn.apache.org/repos/asf/incubator/wicket/branches/WICKET_1_1@459588 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../http/servlet/MultipartServletWebRequest.java   | 72 ++++++++++++++++------
 1 file changed, 53 insertions(+), 19 deletions(-)

diff --git 
a/wicket/src/java/wicket/protocol/http/servlet/MultipartServletWebRequest.java 
b/wicket/src/java/wicket/protocol/http/servlet/MultipartServletWebRequest.java
index b3451e4edd..7d8cceddd0 100644
--- 
a/wicket/src/java/wicket/protocol/http/servlet/MultipartServletWebRequest.java
+++ 
b/wicket/src/java/wicket/protocol/http/servlet/MultipartServletWebRequest.java
@@ -23,7 +23,6 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 
-
 import wicket.WicketRuntimeException;
 import wicket.protocol.http.MultipartWebRequest;
 import wicket.util.lang.Bytes;
@@ -40,6 +39,7 @@ import wicket.util.value.ValueMap;
  * @author Eelco Hillenius
  * @author Cameron Braid
  * @author Ate Douma
+ * @author Igor Vaynberg (ivaynberg)
  */
 public class MultipartServletWebRequest extends ServletWebRequest implements 
MultipartWebRequest
 {
@@ -48,18 +48,22 @@ public class MultipartServletWebRequest extends 
ServletWebRequest implements Mul
 
        /** Map of parameters. */
        private final ValueMap parameters = new ValueMap();
-       
+
        /**
         * Constructor
         * 
-        * @param maxSize the maximum size this request may be
-        * @param request the servlet request
-        * @throws FileUploadException Thrown if something goes wrong with 
upload
+        * @param maxSize
+        *            the maximum size this request may be
+        * @param request
+        *            the servlet request
+        * @throws FileUploadException
+        *             Thrown if something goes wrong with upload
         */
-       public MultipartServletWebRequest(HttpServletRequest request, Bytes 
maxSize) throws FileUploadException
+       public MultipartServletWebRequest(HttpServletRequest request, Bytes 
maxSize)
+                       throws FileUploadException
        {
                super(request);
-               
+
                // Check that request is multipart
                final boolean isMultipart = 
ServletFileUpload.isMultipartContent(request);
                if (!isMultipart)
@@ -67,15 +71,15 @@ public class MultipartServletWebRequest extends 
ServletWebRequest implements Mul
                        throw new IllegalStateException("ServletRequest does 
not contain multipart content");
                }
 
-               DiskFileItemFactory factory = new DiskFileItemFactory();        
        
+               DiskFileItemFactory factory = new DiskFileItemFactory();
 
-        // Configure the factory here, if desired.
-        ServletFileUpload upload = new ServletFileUpload(factory);
-        
-        // The encoding that will be used to decode the string parameters
-        // It should NOT be null at this point, but it may be 
-        // if the older Servlet API 2.2 is used
-        String encoding = request.getCharacterEncoding();
+               // Configure the factory here, if desired.
+               ServletFileUpload upload = new ServletFileUpload(factory);
+
+               // The encoding that will be used to decode the string 
parameters
+               // It should NOT be null at this point, but it may be
+               // if the older Servlet API 2.2 is used
+               String encoding = request.getCharacterEncoding();
 
                // set encoding specifically when we found it
                if (encoding != null)
@@ -112,7 +116,8 @@ public class MultipartServletWebRequest extends 
ServletWebRequest implements Mul
                                {
                                        value = item.getString();
                                }
-                               parameters.put(item.getFieldName(), value);
+
+                               addParameter(item.getFieldName(), value);
                        }
                        else
                        {
@@ -122,6 +127,35 @@ public class MultipartServletWebRequest extends 
ServletWebRequest implements Mul
                }
        }
 
+       /**
+        * Adds a parameter to the parameters value map
+        * 
+        * @param name
+        *            parameter name
+        * @param value
+        *            parameter value
+        */
+       private void addParameter(final String name, final String value)
+       {
+               final String[] currVal = (String[])parameters.get(name);
+
+               String[] newVal = null;
+
+               if (currVal != null)
+               {
+                       newVal = new String[currVal.length + 1];
+                       System.arraycopy(currVal, 0, newVal, 0, currVal.length);
+                       newVal[currVal.length] = value;
+               }
+               else
+               {
+                       newVal = new String[] { value };
+
+               }
+
+               parameters.put(name, newVal);
+       }
+
        /**
         * @return Returns the files.
         */
@@ -147,7 +181,8 @@ public class MultipartServletWebRequest extends 
ServletWebRequest implements Mul
         */
        public String getParameter(final String key)
        {
-               return parameters.getString(key);
+               String[] val = (String[])parameters.get(key);
+               return (val == null) ? null : val[0];
        }
 
        /**
@@ -163,7 +198,6 @@ public class MultipartServletWebRequest extends 
ServletWebRequest implements Mul
         */
        public String[] getParameters(final String key)
        {
-               String val = getParameter(key);
-               return (val != null) ? val.split(",") : null;
+               return (String[])parameters.get(key);
        }
 }

Reply via email to