From 7e44b71d6da055d0aa24728e209c794267bc0c67 Mon Sep 17 00:00:00 2001 From: hns Date: Tue, 9 Aug 2005 13:37:19 +0000 Subject: [PATCH] Normalize upload file names by cutting off any path info before the actual file name. --- src/helma/util/MimePart.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/helma/util/MimePart.java b/src/helma/util/MimePart.java index feb28e8a..5c4bcc1f 100644 --- a/src/helma/util/MimePart.java +++ b/src/helma/util/MimePart.java @@ -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; + } + }