Author: ivaynberg
Date: Tue Nov 11 15:09:58 2008
New Revision: 713218
URL: http://svn.apache.org/viewvc?rev=713218&view=rev
Log:
WICKET-1930
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/file/Files.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java?rev=713218&r1=713217&r2=713218&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java
Tue Nov 11 15:09:58 2008
@@ -186,7 +186,8 @@
*/
public final File writeToTempFile() throws IOException
{
- File temp = File.createTempFile(Session.get().getId(),
item.getFieldName());
+ File temp = File.createTempFile(Session.get().getId(),
+ Files.cleanupFilename(item.getFieldName()));
writeTo(temp);
return temp;
}
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/file/Files.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/file/Files.java?rev=713218&r1=713217&r2=713218&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/file/Files.java
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/file/Files.java
Tue Nov 11 15:09:58 2008
@@ -76,7 +76,7 @@
public static String filename(final String path)
{
return Strings.lastPathComponent(path.replace('/',
java.io.File.separatorChar),
- java.io.File.separatorChar);
+ java.io.File.separatorChar);
}
/**
@@ -92,7 +92,8 @@
if (!file.delete())
{
// NOTE: fix for java/win bug. see:
- //
http://forum.java.sun.com/thread.jsp?forum=4&thread=158689&tstart=0&trange=15
+ //
http://forum.java.sun.com/thread.jsp?forum=4&thread=158689&tstart=
+ // 0&trange=15
System.gc();
try
{
@@ -119,7 +120,7 @@
* @throws IOException
*/
public static final int writeTo(final java.io.File file, final
InputStream input)
- throws IOException
+ throws IOException
{
final FileOutputStream out = new FileOutputStream(file);
try
@@ -132,10 +133,32 @@
}
}
+ private static String FORBIDDEN_IN_NAME = new String("\"*/:<>?\\|,");
+
+ /**
+ * <p>
+ * Replaces commonly unsupported characters with '_'
+ * </p>
+ *
+ * @param filename
+ * to be cleaned
+ * @return cleaned filename
+ */
+ public static final String cleanupFilename(final String filename)
+ {
+ String name = filename;
+ for (int i = 0; i < FORBIDDEN_IN_NAME.length(); i++)
+ {
+ name = name.replace(FORBIDDEN_IN_NAME.charAt(i), '_');
+ }
+ return name;
+ }
+
/**
* Private constructor to prevent instantiation.
*/
private Files()
{
}
+
}