Normalize upload file names by cutting off any path info before the actual file name.

This commit is contained in:
hns 2005-08-09 13:37:19 +00:00
parent 9b97203b3a
commit 7e44b71d6d

View file

@ -39,7 +39,7 @@ public class MimePart implements Serializable {
* @param contentType ...
*/
public MimePart(String name, byte[] content, String contentType) {
this.name = name;
this.name = normalizeFilename(name);
this.content = (content == null) ? new byte[0] : content;
this.contentType = contentType;
contentLength = (content == null) ? 0 : content.length;
@ -189,4 +189,20 @@ public class MimePart implements Serializable {
return null;
}
/**
* Normalize a upload file name. Internet Explorer on Windows sends
* the whole path, so we cut off everything before the actual name.
*/
public static String normalizeFilename(String filename) {
if (filename == null)
return null;
int idx = filename.lastIndexOf('/');
if (idx > -1)
filename = filename.substring(idx + 1);
idx = filename.lastIndexOf('\\');
if (idx > -1)
filename = filename.substring(idx + 1);
return filename;
}
}