Revision: 765
http://stripes.svn.sourceforge.net/stripes/?rev=765&view=rev
Author: bengunter
Date: 2008-01-19 14:07:29 -0800 (Sat, 19 Jan 2008)
Log Message:
-----------
Partial fix for STS-478. An attempt is made in CommonsMultipartWrapper to trim
path information from the file name before creating the FileBean object.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CommonsMultipartWrapper.java
Modified:
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CommonsMultipartWrapper.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CommonsMultipartWrapper.java
2008-01-19 20:12:19 UTC (rev 764)
+++
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/CommonsMultipartWrapper.java
2008-01-19 22:07:29 UTC (rev 765)
@@ -32,6 +32,7 @@
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.regex.Pattern;
/**
* An implementation of MultipartWrapper that uses Jakarta Commons FileUpload
(from apache)
@@ -151,10 +152,20 @@
return null;
}
else {
+ // Attempt to ensure the file name is just the basename with no
path included
+ String basename = item.getName();
+ int index;
+ if (Pattern.compile("(?i:^[A-Z]:\\\\)").matcher(basename).find())
+ index = basename.lastIndexOf('\\');
+ else
+ index = basename.lastIndexOf('/');
+ if (index >= 0 && index + 1 < basename.length() - 1)
+ basename = basename.substring(index + 1);
+
// Use an anonymous inner subclass of FileBean that overrides all
the
// methods that rely on having a File present, to use the FileItem
// created by commons upload instead.
- return new FileBean(null, item.getContentType(), item.getName(),
this.charset) {
+ return new FileBean(null, item.getContentType(), basename,
this.charset) {
@Override public long getSize() { return item.getSize(); }
@Override public InputStream getInputStream() throws
IOException {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development