[FIXED HUDSON-5951] improve normalization of ".." in FilePath

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@30462 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
mindless committed 2010-04-29 07:35:22 +00:00
1 parent 51773e58ec
commit ae837cecf4
2 files changed
+74 -43

No files matched your search

+23 -1
View File
@@ -1,7 +1,7 @@
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Alan Harder
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -113,8 +113,30 @@ public class FilePathTest extends ChannelTestCase {
compare("c:\\abc\\..","c:\\"); // we want c:\\, not c:
compare("c:\\abc\\def\\..","c:\\abc");
compare("/abc/../","/");
compare("abc/..",".");
compare(".",".");
// @Bug(5951)
compare("C:\\Hudson\\jobs\\foo\\workspace/../../otherjob/workspace/build.xml",
"C:\\Hudson\\jobs/otherjob/workspace/build.xml");
// Other cases that failed before
compare("../../abc/def","../../abc/def");
compare("..\\..\\abc\\def","..\\..\\abc\\def");
compare("/abc//../def","/def");
compare("c:\\abc\\\\..\\def","c:\\def");
compare("/../abc/def","/abc/def");
compare("c:\\..\\abc\\def","c:\\abc\\def");
compare("abc/def/","abc/def");
compare("abc\\def\\","abc\\def");
// The new code can collapse extra separator chars
compare("abc//def/\\//\\ghi","abc/def/ghi");
compare("\\\\host\\\\abc\\\\\\def","\\\\host\\abc\\def"); // don't collapse for \\ prefix
compare("\\\\\\foo","\\\\foo");
compare("//foo","/foo");
// Other edge cases
compare("abc/def/../../../ghi","../ghi");
compare("\\abc\\def\\..\\..\\..\\ghi\\","\\ghi");
}
private void compare(String original, String answer) {