Changeset 7382


Ignore:
Timestamp:
Jun 1, 2017, 9:55:19 AM (5 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #2087: Uploading a file with national characters gives incorrect file name

The file upload servlet now uses a character set when creating strings from the upload data. If the browser sets the encoding in the header that is used, otherwise we assume it is UTF-8.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.11-stable/src/clients/web/net/sf/basedb/clients/web/fileupload/FileUpload.java

    r7160 r7382  
    3636import java.io.IOException;
    3737import java.net.SocketTimeoutException;
     38import java.nio.charset.Charset;
    3839
    3940import javax.servlet.ServletRequest;
     
    4142
    4243import net.sf.basedb.util.FileUtil;
     44import net.sf.basedb.util.Values;
    4345
    4446/**
     
    103105  */
    104106  private int transferRate = 0;
     107 
     108  /**
     109    The charset used for decoding header lines.
     110  */
     111  private Charset charset;
    105112
    106113  /**
     
    151158    this.boundary = sectionBoundary.getBytes();
    152159    long contentLength = request.getContentLengthLong();
     160   
     161    String encoding = Values.getString(request.getCharacterEncoding(), "UTF-8");
     162    try
     163    {
     164      this.charset = Charset.forName(encoding);
     165    }
     166    catch (Exception ex)
     167    {
     168      this.charset = Charset.forName("UTF-8");
     169    }
     170   
    153171    this.progress = new FileUploadProgress(contentLength);
    154172    try
     
    484502      if (bytes >= 3)
    485503      {
    486         return new String(line, 0, bytes - 2);  // -2 because we strip CRLF at the end of the line.
     504        return new String(line, 0, bytes - 2, charset); // -2 because we strip CRLF at the end of the line.
    487505      }
    488506      else
     
    522540        if (!status.atBoundary)
    523541        {
    524           sb.append(new String(line, 0, bytes));
     542          sb.append(new String(line, 0, bytes, charset));
    525543        }
    526544      }
Note: See TracChangeset for help on using the changeset viewer.