commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joc...@apache.org
Subject svn commit: r963627 - in /commons/proper/fileupload/trunk/src: java/org/apache/commons/fileupload/util/Streams.java test/org/apache/commons/fileupload/StreamingTest.java
Date Tue, 13 Jul 2010 09:22:04 GMT
Author: jochen
Date: Tue Jul 13 09:22:03 2010
New Revision: 963627

URL: http://svn.apache.org/viewvc?rev=963627&view=rev
Log:
Java 1.3 compatibility fixes.

Modified:
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/Streams.java
    commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/StreamingTest.java

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/Streams.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/Streams.java?rev=963627&r1=963626&r2=963627&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/Streams.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/util/Streams.java
Tue Jul 13 09:22:03 2010
@@ -177,8 +177,21 @@ public final class Streams {
      */
     public static String checkFileName(String pFileName) {
         if (pFileName != null  &&  pFileName.indexOf('\u0000') != -1) {
+            // pFileName.replace("\u0000", "\\0")
+            final StringBuffer sb = new StringBuffer();
+            for (int i = 0;  i < pFileName.length();  i++) {
+                char c = pFileName.charAt(i);
+                switch (c) {
+                    case 0:
+                        sb.append("\\0");
+                        break;
+                    default:
+                        sb.append(c);
+                        break;
+                }
+            }
             throw new InvalidFileNameException(pFileName,
-                    "Invalid file name: " + pFileName.replace("\u0000", "\\0"));
+                    "Invalid file name: " + sb);
         }
         return pFileName;
     }

Modified: commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/StreamingTest.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/StreamingTest.java?rev=963627&r1=963626&r2=963627&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/StreamingTest.java
(original)
+++ commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/StreamingTest.java
Tue Jul 13 09:22:03 2010
@@ -25,7 +25,6 @@ import java.io.OutputStreamWriter;
 import java.util.Iterator;
 import java.util.List;
 import javax.servlet.http.HttpServletRequest;
-import javax.swing.filechooser.FileNameExtensionFilter;
 
 import org.apache.commons.fileupload.FileUploadBase.IOFileUploadException;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
@@ -257,8 +256,8 @@ public class StreamingTest extends TestC
             fail("Expected exception");
         } catch (InvalidFileNameException e) {
             assertEquals(fileName, e.getName());
-            assertFalse(e.getMessage().contains(fileName));
-            assertTrue(e.getMessage().contains("foo.exe\\0.png"));
+            assertTrue(e.getMessage().indexOf(fileName) == -1);
+            assertTrue(e.getMessage().indexOf("foo.exe\\0.png") != -1);
         }
 
         List fileItems = parseUpload(reqBytes);
@@ -268,8 +267,8 @@ public class StreamingTest extends TestC
             fail("Expected exception");
         } catch (InvalidFileNameException e) {
             assertEquals(fileName, e.getName());
-            assertFalse(e.getMessage().contains(fileName));
-            assertTrue(e.getMessage().contains("foo.exe\\0.png"));
+            assertTrue(e.getMessage().indexOf(fileName) == -1);
+            assertTrue(e.getMessage().indexOf("foo.exe\\0.png") != -1);
         }
     }
 }



Mime
View raw message