commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mart...@apache.org
Subject cvs commit: jakarta-commons/fileupload/src/java/org/apache/commons/fileupload FileUploadBase.java
Date Sat, 16 Oct 2004 18:17:50 GMT
martinc     2004/10/16 11:17:50

  Modified:    fileupload/src/java/org/apache/commons/fileupload
                        FileUploadBase.java
  Log:
  Bug #25527 - Handle unquoted header parameters.
  
  Revision  Changes    Path
  1.10      +25 -9     jakarta-commons/fileupload/src/java/org/apache/commons/fileupload/FileUploadBase.java
  
  Index: FileUploadBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/fileupload/src/java/org/apache/commons/fileupload/FileUploadBase.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FileUploadBase.java	11 Oct 2004 05:06:33 -0000	1.9
  +++ FileUploadBase.java	16 Oct 2004 18:17:50 -0000	1.10
  @@ -405,11 +405,23 @@
           String cd = getHeader(headers, CONTENT_DISPOSITION);
           if (cd.startsWith(FORM_DATA) || cd.startsWith(ATTACHMENT))
           {
  -            int start = cd.indexOf("filename=\"");
  -            int end = cd.indexOf('"', start + 10);
  -            if (start != -1 && end != -1)
  +            ParameterParser parser = new ParameterParser();
  +            parser.setLowerCaseNames(true);
  +            // Parameter parser can handle null input
  +            Map params = parser.parse(cd, ';');
  +            if (params.containsKey("filename"))
               {
  -                fileName = cd.substring(start + 10, end).trim();
  +                fileName = (String)params.get("filename");
  +                if (fileName != null)
  +                {
  +                    fileName = fileName.trim();
  +                }
  +                else
  +                {
  +                    // Even if there is no value, the parameter is present, so
  +                    // we return an empty file name rather than no file name.
  +                    fileName = "";
  +                }
               }
           }
           return fileName;
  @@ -430,11 +442,15 @@
           String cd = getHeader(headers, CONTENT_DISPOSITION);
           if (cd != null && cd.startsWith(FORM_DATA))
           {
  -            int start = cd.indexOf("name=\"");
  -            int end = cd.indexOf('"', start + 6);
  -            if (start != -1 && end != -1)
  +
  +            ParameterParser parser = new ParameterParser();
  +            parser.setLowerCaseNames(true);
  +            // Parameter parser can handle null input
  +            Map params = parser.parse(cd, ';');
  +            fieldName = (String)params.get("name");
  +            if (fieldName != null)
               {
  -                fieldName = cd.substring(start + 6, end);
  +                fieldName = fieldName.trim();
               }
           }
           return fieldName;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message