mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-14 20:42:21 +00:00
[FIXED HUDSON-6494] fix FilePath.getParent() so parent of /foo is /
(not "."), and handle edge case so path with no parent ("/" or "abc")
returns null instead of getting IndexOutOfBoundsException.
(returning null is consistent with File.getParentFile())
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@30917 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
980f6893bb
commit
ed81cd5f54
2 files changed
+23
-5
No files matched your search
@@ -142,4 +142,22 @@ public class FilePathTest extends ChannelTestCase {
|
||||
private void compare(String original, String answer) {
|
||||
assertEquals(answer,new FilePath((VirtualChannel)null,original).getRemote());
|
||||
}
|
||||
|
||||
// @Bug(6494)
|
||||
public void testGetParent() throws Exception {
|
||||
FilePath fp = new FilePath((VirtualChannel)null, "/abc/def");
|
||||
assertEquals("/abc", (fp = fp.getParent()).getRemote());
|
||||
assertEquals("/", (fp = fp.getParent()).getRemote());
|
||||
assertNull(fp.getParent());
|
||||
|
||||
fp = new FilePath((VirtualChannel)null, "abc/def\\ghi");
|
||||
assertEquals("abc/def", (fp = fp.getParent()).getRemote());
|
||||
assertEquals("abc", (fp = fp.getParent()).getRemote());
|
||||
assertNull(fp.getParent());
|
||||
|
||||
fp = new FilePath((VirtualChannel)null, "C:\\abc\\def");
|
||||
assertEquals("C:\\abc", (fp = fp.getParent()).getRemote());
|
||||
assertEquals("C:\\", (fp = fp.getParent()).getRemote());
|
||||
assertNull(fp.getParent());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user