You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2008/11/12 00:13:23 UTC
svn commit: r713219 - in
/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket:
markup/html/form/upload/FileUpload.java util/file/Files.java
Author: ivaynberg
Date: Tue Nov 11 15:13:22 2008
New Revision: 713219
URL: http://svn.apache.org/viewvc?rev=713219&view=rev
Log:
WICKET-1930
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/file/Files.java
Modified: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java?rev=713219&r1=713218&r2=713219&view=diff
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java (original)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUpload.java Tue Nov 11 15:13:22 2008
@@ -187,7 +187,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/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/file/Files.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/file/Files.java?rev=713219&r1=713218&r2=713219&view=diff
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/file/Files.java (original)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/file/Files.java Tue Nov 11 15:13:22 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()
{
}
+
}