cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/servlet/multipart MultipartParser.java
Date Thu, 11 Mar 2004 15:32:41 GMT
sylvain     2004/03/11 07:32:41

  Modified:    src/java/org/apache/cocoon/servlet/multipart
                        MultipartParser.java
  Log:
  Ensure that correct encoding is used to parse headers and values (problem revealed by filenames
with accented letters)
  
  Revision  Changes    Path
  1.7       +14 -12    cocoon-2.1/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java
  
  Index: MultipartParser.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/servlet/multipart/MultipartParser.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MultipartParser.java	5 Mar 2004 13:02:58 -0000	1.6
  +++ MultipartParser.java	11 Mar 2004 15:32:41 -0000	1.7
  @@ -30,6 +30,8 @@
   
   import javax.servlet.http.HttpServletRequest;
   
  +import org.apache.avalon.excalibur.io.IOUtil;
  +
   /**
    * This class is used to implement a multipart request wrapper.
    * It will parse the http post stream and and fill it's hashtable with values.
  @@ -96,7 +98,6 @@
           }
   
           this.parts = new Hashtable();
  -
           BufferedInputStream bufferedStream = new BufferedInputStream(requestStream);
           PushbackInputStream pushbackStream = new PushbackInputStream(bufferedStream, MAX_BOUNDARY_SIZE);
           TokenStream stream = new TokenStream(pushbackStream);
  @@ -255,14 +256,14 @@
       private void parseInlinePart(TokenStream in, Hashtable headers)
               throws IOException {
   
  -        byte[] buf = new byte[INLINE_BUFFER_SIZE];
  -        StringBuffer value = new StringBuffer();
  +		// Buffer incoming bytes for proper string decoding (there can be multibyte chars)
  +        ByteArrayOutputStream bos = new ByteArrayOutputStream();
   
           while (in.getState() == TokenStream.STATE_READING) {
  -            int read = in.read(buf);
  -            value.append(new String(buf, 0, read, this.characterEncoding));
  +        	int c = in.read();
  +        	if (c != -1) bos.write(c);
           }
  -
  +        
           String field = (String) headers.get("name");
           Vector v = (Vector) this.parts.get(field);
   
  @@ -271,7 +272,7 @@
               this.parts.put(field, v);
           }
   
  -        v.add(value.toString());
  +        v.add(new String(bos.toByteArray(), this.characterEncoding));
       }
   
       /**
  @@ -335,12 +336,13 @@
        * @throws IOException
        */
       private String readln(TokenStream in) throws IOException {
  -
  -        StringBuffer out = new StringBuffer();
  +    	
  +    	ByteArrayOutputStream bos = new ByteArrayOutputStream();
  +    	
           int b = in.read();
   
           while ((b != -1) && (b != '\r')) {
  -            out.append((char) b);
  +            bos.write(b);
               b = in.read();
           }
   
  @@ -348,6 +350,6 @@
               in.read();    // read '\n'
           }
   
  -        return out.toString();
  +        return new String(bos.toByteArray(), this.characterEncoding);
       }
   }
  
  
  

Mime
View raw message