perform path normalization to get rid of "." and ".." in the path.

Without it, FilePath.getParent() and File.getParent() doesn't work correctly.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@27956 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2010-02-26 00:30:15 +00:00
1 parent 439243f3ba
commit 787d843d3d
2 files changed
+85 -5

No files matched your search

@@ -23,6 +23,7 @@
*/
package hudson;
import hudson.remoting.VirtualChannel;
import hudson.util.NullStream;
import java.io.File;
@@ -71,4 +72,32 @@ public class FilePathTest extends ChannelTestCase {
Util.deleteRecursive(tmp);
}
}
public void testNormalization() throws Exception {
compare("abc/def\\ghi","abc/def\\ghi"); // allow mixed separators
{// basic '.' trimming
compare("./abc/def","abc/def");
compare("abc/./def","abc/def");
compare("abc/def/.","abc/def");
compare(".\\abc\\def","abc\\def");
compare("abc\\.\\def","abc\\def");
compare("abc\\def\\.","abc\\def");
}
compare("abc/../def","def");
compare("abc/def/../../ghi","ghi");
compare("abc/./def/../././../ghi","ghi"); // interleaving . and ..
compare("../abc/def","../abc/def"); // uncollapsible ..
compare("abc/def/..","abc");
compare("c:\\abc\\..","c:\\"); // we want c:\\, not c:
compare("c:\\abc\\def\\..","c:\\abc");
}
private void compare(String original, String answer) {
assertEquals(answer,new FilePath((VirtualChannel)null,original).getRemote());
}
}