You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/04/22 19:52:02 UTC
svn commit: r1470636 - in /commons/proper/io/trunk/src: changes/changes.xml
main/java/org/apache/commons/io/FilenameUtils.java
test/java/org/apache/commons/io/FilenameUtilsTestCase.java
Author: sebb
Date: Mon Apr 22 17:52:02 2013
New Revision: 1470636
URL: http://svn.apache.org/r1470636
Log:
IO-299 getPrefixLength returns null if filename has leading slashes
Javadoc: add examples to show correct behaviour; add unit tests
Modified:
commons/proper/io/trunk/src/changes/changes.xml
commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java
commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
Modified: commons/proper/io/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/changes/changes.xml?rev=1470636&r1=1470635&r2=1470636&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Mon Apr 22 17:52:02 2013
@@ -48,6 +48,10 @@ The <action> type attribute can be add,u
<!-- The release date is the date RC is cut -->
<release version="2.5" date="2013-??-??" description="New features and bug fixes.">
<action issue="IO-328" dev="sebb" type="update">
+ getPrefixLength returns null if filename has leading slashes
+ Javadoc: add examples to show correct behaviour; add unit tests
+ </action>
+ <action issue="IO-299" dev="sebb" type="update">
FileUtils.listFilesAndDirs includes original dir in results even when it doesn't match filter
Javadoc: clarify that original dir is included in the results
</action>
Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java?rev=1470636&r1=1470635&r2=1470636&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/FilenameUtils.java Mon Apr 22 17:52:02 2013
@@ -603,6 +603,7 @@ public class FilenameUtils {
* C:a\b\c.txt --> "C:" --> drive relative
* C:\a\b\c.txt --> "C:\" --> absolute
* \\server\a\b\c.txt --> "\\server\" --> UNC
+ * \\\a\b\c.txt --> error, length = -1
*
* Unix:
* a/b/c.txt --> "" --> relative
@@ -611,11 +612,17 @@ public class FilenameUtils {
* ~ --> "~/" --> current user (slash added)
* ~user/a/b/c.txt --> "~user/" --> named user
* ~user --> "~user/" --> named user (slash added)
+ * //server/a/b/c.txt --> "//server/"
+ * ///a/b/c.txt --> error, length = -1
* </pre>
* <p>
* The output will be the same irrespective of the machine that the code is running on.
* ie. both Unix and Windows prefixes are matched regardless.
*
+ * Note that a leading // (or \\) is used to indicate a UNC name on Windows.
+ * These must be followed by a server name, so double-slashes are not collapsed
+ * to a single slash at the start of the filename.
+ *
* @param filename the filename to find the prefix in, null returns -1
* @return the length of the prefix, -1 if invalid or null
*/
Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java?rev=1470636&r1=1470635&r2=1470636&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java Mon Apr 22 17:52:02 2013
@@ -503,7 +503,11 @@ public class FilenameUtilsTestCase exten
assertEquals(1, FilenameUtils.getPrefixLength("\\a\\b\\c.txt"));
assertEquals(2, FilenameUtils.getPrefixLength("~\\a\\b\\c.txt"));
assertEquals(6, FilenameUtils.getPrefixLength("~user\\a\\b\\c.txt"));
- }
+
+ assertEquals(9, FilenameUtils.getPrefixLength("//server/a/b/c.txt"));
+ assertEquals(-1, FilenameUtils.getPrefixLength("\\\\\\a\\b\\c.txt"));
+ assertEquals(-1, FilenameUtils.getPrefixLength("///a/b/c.txt"));
+}
public void testIndexOfLastSeparator() {
assertEquals(-1, FilenameUtils.indexOfLastSeparator(null));