Bug in handling multiple values in multipart forms

2001-03-01 Thread Till Nagel

Hi,

I've encountered a bug in handling multipart requests.
(last nightly build 20010224)

If a form is sent with enctype="multipart/form-data" the multiple values
(e.g. select multiple...) aren't set correctly. In the
DiskMultipartRequestHandler the values are stored in a Hashtable thus only
the last one of the values is set in the Form.

A possible solution:

old DiskMultiPartRequestHandler.java @ line 71

if (!element.isFile())

  textElements.put(element.getName(), element.getValue());
  allElements.put(element.getName(), element.getValue());
}

---

new DiskMultiPartRequestHandler.java

if (!element.isFile())

 String name = element.getName();
 String value = element.getValue();

 Object oldValue = textElements.get(name);
 if (oldValue != null) {
   String[] oldValues = new String[1];

   try {
 oldValues = (String[]) oldValue;
   } catch (ClassCastException e) {
 oldValues[0] = (String) oldValue;
   }
   int length = oldValues.length;

   String[] newValue = new String[length + 1];
   for (int i = 0; i  length; i++) {
 newValue[i] = oldValues[i];
   }
   newValue[length] = value;

   textElements.put(name, newValue);
   allElements.put(name, newValue);

 } else {
   textElements.put(name, value);
   allElements.put(name, value);
 }
}



Regards,
Till

P.S. Any hints to
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg02713.html ?







RE: Bug in handling multiple values in multipart forms

2001-03-01 Thread Schachter, Michael

Till,

Thanks, I'll include this with the other patch I'm working on to improve the
speed of multipart requests.

-Original Message-
From: Till Nagel [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 01, 2001 3:12 PM
To: [EMAIL PROTECTED]
Subject: Bug in handling multiple values in multipart forms


Hi,

I've encountered a bug in handling multipart requests.
(last nightly build 20010224)

If a form is sent with enctype="multipart/form-data" the multiple values
(e.g. select multiple...) aren't set correctly. In the
DiskMultipartRequestHandler the values are stored in a Hashtable thus only
the last one of the values is set in the Form.

A possible solution:

old DiskMultiPartRequestHandler.java @ line 71

if (!element.isFile())

  textElements.put(element.getName(), element.getValue());
  allElements.put(element.getName(), element.getValue());
}

---

new DiskMultiPartRequestHandler.java

if (!element.isFile())

 String name = element.getName();
 String value = element.getValue();

 Object oldValue = textElements.get(name);
 if (oldValue != null) {
   String[] oldValues = new String[1];

   try {
 oldValues = (String[]) oldValue;
   } catch (ClassCastException e) {
 oldValues[0] = (String) oldValue;
   }
   int length = oldValues.length;

   String[] newValue = new String[length + 1];
   for (int i = 0; i  length; i++) {
 newValue[i] = oldValues[i];
   }
   newValue[length] = value;

   textElements.put(name, newValue);
   allElements.put(name, newValue);

 } else {
   textElements.put(name, value);
   allElements.put(name, value);
 }
}



Regards,
Till

P.S. Any hints to
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg02713.html ?