commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r240438 - in /jakarta/commons/proper/io/trunk/src: java/org/apache/commons/io/FilenameUtils.java test/org/apache/commons/io/FilenameUtilsTestCase.java
Date Sat, 27 Aug 2005 16:47:07 GMT
Author: scolebourne
Date: Sat Aug 27 09:47:00 2005
New Revision: 240438

URL: http://svn.apache.org/viewcvs?rev=240438&view=rev
Log:
Handle Windows drive relative paths like C:a\b\c

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

Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java?rev=240438&r1=240437&r2=240438&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java (original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FilenameUtils.java Sat
Aug 27 09:47:00 2005
@@ -358,10 +358,11 @@
      * <pre>
      * Windows:
      * a\b\c.txt           --> ""          --> relative
-     * \a\b\c.txt          --> "\"         --> drive relative
+     * \a\b\c.txt          --> "\"         --> drive absolute
+     * C:a\b\c.txt         --> "C:"        --> drive relative
      * C:\a\b\c.txt        --> "C:\"       --> absolute
      * \\server\a\b\c.txt  --> "\\server\" --> UNC
-     * 
+     *
      * Unix:
      * a/b/c.txt           --> ""          --> relative
      * /a/b/c.txt          --> "/"         --> absolute
@@ -406,10 +407,13 @@
             char ch1 = filename.charAt(1);
             if (ch1 == ':') {
                 ch0 = Character.toUpperCase(ch0);
-                if (ch0 < 'A' || ch0 > 'Z' || len == 2 || isSeparator(filename.charAt(2))
== false) {
-                    return -1;
+                if (ch0 >= 'A' && ch0 <= 'Z') {
+                    if (len == 2 || isSeparator(filename.charAt(2)) == false) {
+                        return 2;
+                    }
+                    return 3;
                 }
-                return 3;
+                return -1;
                 
             } else if (isSeparator(ch0) && isSeparator(ch1)) {
                 int posUnix = filename.indexOf(UNIX_SEPARATOR, 2);
@@ -478,7 +482,8 @@
      * <pre>
      * Windows:
      * a\b\c.txt           --> ""          --> relative
-     * \a\b\c.txt          --> "\"         --> drive relative
+     * \a\b\c.txt          --> "\"         --> drive absolute
+     * C:a\b\c.txt         --> "C:"        --> drive relative
      * C:\a\b\c.txt        --> "C:\"       --> absolute
      * \\server\a\b\c.txt  --> "\\server\" --> UNC
      * 

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FilenameUtilsTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FilenameUtilsTestCase.java?rev=240438&r1=240437&r2=240438&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FilenameUtilsTestCase.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FilenameUtilsTestCase.java
Sat Aug 27 09:47:00 2005
@@ -285,6 +285,7 @@
         
         assertEquals(0, FilenameUtils.getPrefixLength("a\\b\\c.txt"));
         assertEquals(1, FilenameUtils.getPrefixLength("\\a\\b\\c.txt"));
+        assertEquals(2, FilenameUtils.getPrefixLength("C:a\\b\\c.txt"));
         assertEquals(3, FilenameUtils.getPrefixLength("C:\\a\\b\\c.txt"));
         assertEquals(9, FilenameUtils.getPrefixLength("\\\\server\\a\\b\\c.txt"));
         



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message