commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r721610 - in /commons/proper/io/trunk/src: java/org/apache/commons/io/FilenameUtils.java test/org/apache/commons/io/FilenameUtilsTestCase.java
Date Sat, 29 Nov 2008 01:50:12 GMT
Author: niallp
Date: Fri Nov 28 17:50:11 2008
New Revision: 721610

URL: http://svn.apache.org/viewvc?rev=721610&view=rev
Log:
Fix for IO-179 StringIndexOutOfBounds exception on FilenameUtils.getPathNoEndSeparator - thanks
to Francisco Borges for the patch

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=721610&r1=721609&r2=721610&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 Nov 28 17:50:11
2008
@@ -699,10 +699,11 @@
             return null;
         }
         int index = indexOfLastSeparator(filename);
-        if (prefix >= filename.length() || index < 0) {
+        int endIndex = index+separatorAdd;
+        if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
             return "";
         }
-        return filename.substring(prefix, index + separatorAdd);
+        return filename.substring(prefix, endIndex);
     }
 
     /**

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=721610&r1=721609&r2=721610&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
Nov 28 17:50:11 2008
@@ -556,6 +556,8 @@
     public void testGetPath() {
         assertEquals(null, FilenameUtils.getPath(null));
         assertEquals("", FilenameUtils.getPath("noseperator.inthispath"));
+        assertEquals("", FilenameUtils.getPath("/noseperator.inthispath"));
+        assertEquals("", FilenameUtils.getPath("\\noseperator.inthispath"));
         assertEquals("a/b/", FilenameUtils.getPath("a/b/c.txt"));
         assertEquals("a/b/", FilenameUtils.getPath("a/b/c"));
         assertEquals("a/b/c/", FilenameUtils.getPath("a/b/c/"));
@@ -590,6 +592,8 @@
     public void testGetPathNoEndSeparator() {
         assertEquals(null, FilenameUtils.getPath(null));
         assertEquals("", FilenameUtils.getPath("noseperator.inthispath"));
+        assertEquals("", FilenameUtils.getPathNoEndSeparator("/noseperator.inthispath"));
+        assertEquals("", FilenameUtils.getPathNoEndSeparator("\\noseperator.inthispath"));
         assertEquals("a/b", FilenameUtils.getPathNoEndSeparator("a/b/c.txt"));
         assertEquals("a/b", FilenameUtils.getPathNoEndSeparator("a/b/c"));
         assertEquals("a/b/c", FilenameUtils.getPathNoEndSeparator("a/b/c/"));



Mime
View raw message