Repository: wicket
Updated Branches:
  refs/heads/wicket-1.5.x 8d1378cf8 -> 485404aff


Move #checkFileName() to Files because it doesn't deal with IO streams

Actually execute the check.
Fix Javadoc problems.


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/485404af
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/485404af
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/485404af

Branch: refs/heads/wicket-1.5.x
Commit: 485404affd9adb71d89207383b560fca2bbbb11b
Parents: 8d1378c
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Sat Aug 13 14:13:40 2016 +0200
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Sat Aug 13 14:13:40 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/wicket/util/file/Files.java | 36 ++++++++++++++++++++
 .../java/org/apache/wicket/util/io/Streams.java | 35 -------------------
 .../apache/wicket/util/upload/DiskFileItem.java | 14 ++++----
 3 files changed, 42 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/485404af/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java 
b/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
index 4e89a7b..8408b6f 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/file/Files.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLDecoder;
+import java.security.InvalidParameterException;
 
 import org.apache.wicket.util.io.IOUtils;
 import org.apache.wicket.util.io.Streams;
@@ -471,4 +472,39 @@ public class Files
                logger.error("Failed to create directory: " + folder);
                return false;
        }
+
+       /**
+        * Checks, whether the given file name is valid in the sense, that it
+        * doesn't contain any NUL characters. If the file name is valid, it 
will be
+        * returned without any modifications. Otherwise, an
+        * {@link InvalidParameterException} will be thrown.
+        *
+        * @param fileName
+        *            The file name to check
+        * @return Unmodified file name, if valid.
+        * @throws InvalidParameterException
+        *             If the file name was found to be invalid.
+        */
+       public static String checkFileName(String fileName)
+       {
+               if (fileName != null && fileName.indexOf('\u0000') != -1)
+               {
+                       final StringBuilder sb = new StringBuilder();
+                       for (int i = 0; i < fileName.length(); i++)
+                       {
+                               char c = fileName.charAt(i);
+                               switch (c)
+                               {
+                                       case 0 :
+                                               sb.append("\\0");
+                                               break;
+                                       default :
+                                               sb.append(c);
+                                               break;
+                               }
+                       }
+                       throw new InvalidParameterException("Invalid file name: 
" + sb);
+               }
+               return fileName;
+       }
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/485404af/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java 
b/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
index f2fc907..1c4519d 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/io/Streams.java
@@ -206,41 +206,6 @@ public final class Streams
        }
 
        /**
-        * Checks, whether the given file name is valid in the sense, that it
-        * doesn't contain any NUL characters. If the file name is valid, it 
will be
-        * returned without any modifications. Otherwise, an
-        * {@link InvalidFileNameException} is raised.
-        *
-        * @param fileName
-        *            The file name to check
-        * @return Unmodified file name, if valid.
-        * @throws InvalidFileNameException
-        *             The file name was found to be invalid.
-        */
-       public static String checkFileName(String fileName)
-       {
-               if (fileName != null && fileName.indexOf('\u0000') != -1)
-               {
-                       final StringBuilder sb = new StringBuilder();
-                       for (int i = 0; i < fileName.length(); i++)
-                       {
-                               char c = fileName.charAt(i);
-                               switch (c)
-                               {
-                                       case 0 :
-                                               sb.append("\\0");
-                                               break;
-                                       default :
-                                               sb.append(c);
-                                               break;
-                               }
-                       }
-                       throw new InvalidParameterException("Invalid file name: 
" + sb);
-               }
-               return fileName;
-       }
-       
-       /**
         * Private to prevent instantiation.
         */
        private Streams()

http://git-wip-us.apache.org/repos/asf/wicket/blob/485404af/wicket-util/src/main/java/org/apache/wicket/util/upload/DiskFileItem.java
----------------------------------------------------------------------
diff --git 
a/wicket-util/src/main/java/org/apache/wicket/util/upload/DiskFileItem.java 
b/wicket-util/src/main/java/org/apache/wicket/util/upload/DiskFileItem.java
index 5ad6350..c4ec5ae 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/upload/DiskFileItem.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/upload/DiskFileItem.java
@@ -48,8 +48,8 @@ import org.slf4j.LoggerFactory;
  * 
  * <p>
  * After retrieving an instance of this class from a
- * {@link org.apache.wicket.util.upload.DiskFileUpload DiskFileUpload} 
instance (see
- * {@link org.apache.wicket.util.upload.DiskFileUpload 
#parseRequest(javax.servlet.http.HttpServletRequest)}
+ * {@link org.apache.wicket.util.upload.FileUpload DiskFileUpload} instance 
(see
+ * {@link 
org.apache.wicket.util.upload.FileUpload#parseRequest(RequestContext)}
  * ), you may either request all contents of file at once using {@link #get()} 
or request an
  * {@link java.io.InputStream InputStream} with {@link #getInputStream()} and 
process the file
  * without attempting to load it into memory, which may come handy with large 
files.
@@ -59,7 +59,7 @@ import org.slf4j.LoggerFactory;
  * Temporary files are automatically deleted as soon as they are no longer 
needed. (More precisely,
  * when the corresponding instance of {@link java.io.File} is garbage 
collected.) This is done by
  * the so-called reaper thread, which is started automatically when the class
- * {@link org.apache.commons.io.FileCleaner} is loaded. It might make sense to 
terminate that
+ * {@link org.apache.wicket.util.file.FileCleaner} is loaded. It might make 
sense to terminate that
  * thread, for example, if your web application ends. See the section on 
"Resource cleanup" in the
  * users guide of commons-fileupload.
  * </p>
@@ -601,11 +601,7 @@ public class DiskFileItem implements FileItem, 
FileItemHeadersSupport
                        File tempDir = repository;
                        if (tempDir == null)
                        {
-                               if (repository != null)
-                               {
-                                       
Streams.checkFileName(repository.getPath());
-                               }
-                               String systemTmp = null;
+                               String systemTmp;
                                try
                                {
                                        systemTmp = 
System.getProperty("java.io.tmpdir");
@@ -620,6 +616,8 @@ public class DiskFileItem implements FileItem, 
FileItemHeadersSupport
                                tempDir = new File(systemTmp);
                        }
 
+                       Files.checkFileName(tempDir.getPath());
+
                        try
                        {
                                do

Reply via email to