Browse Source

removeLeadingPath doesn't work if leading is a filesystem root - found by Antoine

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274887 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
e955e3d961
2 changed files with 15 additions and 4 deletions
  1. +6
    -4
      src/main/org/apache/tools/ant/util/FileUtils.java
  2. +9
    -0
      src/testcases/org/apache/tools/ant/util/FileUtilsTest.java

+ 6
- 4
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -1186,10 +1186,12 @@ public class FileUtils {
return "";
}

// if leading's path ends with a slash, it will be stripped by
// normalize - we always add one so we never think /foo was a
// parent directory of /foobar
l += File.separator;
// ensure that l ends with a /
// so we never think /foo was a parent directory of /foobar
if (!l.endsWith("/")) {
l += File.separator;
}

if (p.startsWith(l)) {
return p.substring(l.length());
} else {


+ 9
- 0
src/testcases/org/apache/tools/ant/util/FileUtilsTest.java View File

@@ -421,6 +421,15 @@ public class FileUtilsTest extends TestCase {
new File("/foo/bar/")));
assertEquals("", fu.removeLeadingPath(new File("/foo/bar/"),
new File("/foo/bar")));

String expected = "foo/bar".replace('\\', File.separatorChar)
.replace('/', File.separatorChar);
assertEquals(expected, fu.removeLeadingPath(new File("/"),
new File("/foo/bar")));
assertEquals(expected, fu.removeLeadingPath(new File("c:/"),
new File("c:/foo/bar")));
assertEquals(expected, fu.removeLeadingPath(new File("c:\\"),
new File("c:\\foo\\bar")));
}

/**


Loading…
Cancel
Save