Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-1911

File Upload: content-type validation fails when no file is uploaded

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.6, 2.0.7, 2.0.8, 2.0.9, 2.1.0
    • 2.0.10
    • None
    • FireFox 2.0; Tomcat 5.0; commons-fileupload 1.2

    • Patch

    Description

      If you set allowed types on the file upload interceptor:
      <param name="fileUpload.allowedTypes">image/png,image/gif,image/jpeg</param>

      it will validate content type even though there is no file uploaded.
      This shows up in two cases:
      1) If field is required you will get 2 messages:
      Content-Type not allowed: image "upload_1120a017_1125f7d74fc__8000_00000013.tmp" application/octet-stream
      Image is required.

      2) If field is not required you will get invalid content type validation error anyway (which prohibits from executing the action):
      Content-Type not allowed: image "upload_1120a017_1125f7d74fc__8000_00000013.tmp" application/octet-stream

      Basically it violates the idea of single purpose validator (since it also acts as required field validator).

      There are at least 3 ways to fix it:
      1) fix org.apache.struts2.interceptor.FileUploadInterceptor.acceptFile method so it does not check content type (allowedTypesSet) if file is empty.
      2) fix the ServletFileUpload.parseRequest so it does not show empty downloads (i.e. when file name is null).
      3) (one that is in patch) fix org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.parse so it ignores files that have blank file name.

      Attached patch fixes JakartaMultiPartRequest if file name is blank it means no file has been uploaded.

      Attachments

        1. patch.txt
          1 kB
          Lukasz Racon

        Issue Links

          Activity

            People

              jholmes James Holmes
              lukaszracon Lukasz Racon
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: