commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r584325 - in /commons/proper/io/trunk/src: java/org/apache/commons/io/FilenameUtils.java test/org/apache/commons/io/FilenameUtilsTestCase.java
Date Fri, 12 Oct 2007 23:36:15 GMT
Author: niallp
Date: Fri Oct 12 16:36:12 2007
New Revision: 584325

URL: http://svn.apache.org/viewvc?rev=584325&view=rev
Log:
IO-128 - currently file name "normalization" errors in the equals method causes a mis-leading
NullPointerException. Adding a check for this and throwing an IllegalArgumentException with
a better message should improve the user experience.

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java
    commons/proper/io/trunk/src/test/org/apache/commons/io/FilenameUtilsTestCase.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java?rev=584325&r1=584324&r2=584325&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java Fri Oct 12 16:36:12
2007
@@ -977,6 +977,10 @@
         if (normalized) {
             filename1 = normalize(filename1);
             filename2 = normalize(filename2);
+            if (filename1 == null || filename2 == null) {
+                throw new IllegalArgumentException(
+                    "Error normalizing one or both of the file names");
+            }
         }
         if (caseSensitivity == null) {
             caseSensitivity = IOCase.SENSITIVE;

Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/FilenameUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/FilenameUtilsTestCase.java?rev=584325&r1=584324&r2=584325&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/FilenameUtilsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/FilenameUtilsTestCase.java Fri
Oct 12 16:36:12 2007
@@ -784,6 +784,30 @@
         assertEquals(false, FilenameUtils.equalsNormalizedOnSystem("a/b/", "a/b"));
     }
 
+    /**
+     * Test for https://issues.apache.org/jira/browse/IO-128
+     */
+    public void testEqualsNormalizedError_IO_128() {
+        try {
+            FilenameUtils.equalsNormalizedOnSystem("//file.txt", "file.txt");
+            fail("Invalid normalized first file");
+        } catch(IllegalArgumentException e) {
+            // expected result
+        }
+        try {
+            FilenameUtils.equalsNormalizedOnSystem("file.txt", "//file.txt");
+            fail("Invalid normalized second file");
+        } catch(IllegalArgumentException e) {
+            // expected result
+        }
+        try {
+            FilenameUtils.equalsNormalizedOnSystem("//file.txt", "//file.txt");
+            fail("Invalid normalized both filse");
+        } catch(IllegalArgumentException e) {
+            // expected result
+        }
+    }
+
     public void testEquals_fullControl() {
         assertEquals(false, FilenameUtils.equals("file.txt", "FILE.TXT", true, IOCase.SENSITIVE));
         assertEquals(true, FilenameUtils.equals("file.txt", "FILE.TXT", true, IOCase.INSENSITIVE));



Mime
View raw message