Skip to content

Commit 9e61227

Browse files
author
Niall Pemberton
committed
IO-248 FilenameUtils - getFullPathNoEndSeparator returns empty while path is a one level directory - thanks to hippo spark for the patch
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1002806 13f79535-47bb-0310-9956-ffa450edef68
1 parent 709699a commit 9e61227

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/java/org/apache/commons/io/FilenameUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,9 @@ private static String doGetFullPath(String filename, boolean includeSeparator) {
887887
return filename.substring(0, prefix);
888888
}
889889
int end = index + (includeSeparator ? 1 : 0);
890+
if (end == 0) {
891+
end++;
892+
}
890893
return filename.substring(0, end);
891894
}
892895

src/test/org/apache/commons/io/FilenameUtilsTestCase.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,24 @@ public void testGetFullPathNoEndSeparator() {
704704
assertEquals("~user/a/b", FilenameUtils.getFullPathNoEndSeparator("~user/a/b/c.txt"));
705705
}
706706

707+
/**
708+
* Test for https://issues.apache.org/jira/browse/IO-248
709+
*/
710+
public void testGetFullPathNoEndSeparator_IO_248() {
711+
712+
// Test single separator
713+
assertEquals("/", FilenameUtils.getFullPathNoEndSeparator("/"));
714+
assertEquals("\\", FilenameUtils.getFullPathNoEndSeparator("\\"));
715+
716+
// Test one level directory
717+
assertEquals("/", FilenameUtils.getFullPathNoEndSeparator("/abc"));
718+
assertEquals("\\", FilenameUtils.getFullPathNoEndSeparator("\\abc"));
719+
720+
// Test one level directory
721+
assertEquals("/abc", FilenameUtils.getFullPathNoEndSeparator("/abc/xyz"));
722+
assertEquals("\\abc", FilenameUtils.getFullPathNoEndSeparator("\\abc\\xyz"));
723+
}
724+
707725
public void testGetName() {
708726
assertEquals(null, FilenameUtils.getName(null));
709727
assertEquals("noseperator.inthispath", FilenameUtils.getName("noseperator.inthispath"));

0 commit comments

Comments
 (0)