From f40cbc60b34a952432e7abfb70181d0feabd4dd6 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 10 Jun 2002 06:19:32 +0000 Subject: [PATCH] Merge over a bug-fix needed to get jakarta-tomcat built by Gump. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272855 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/util/FileUtils.java | 12 ++++++------ .../org/apache/tools/ant/util/FileUtilsTest.java | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index b6a5dc8ae..45f992620 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -866,14 +866,14 @@ public class FileUtils { * @since Ant 1.5 */ public String removeLeadingPath(File leading, File path) { - String l = normalize(leading.getAbsolutePath()).getAbsolutePath(); + // 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 + String l = normalize(leading.getAbsolutePath()).getAbsolutePath() + + File.separator; String p = normalize(path.getAbsolutePath()).getAbsolutePath(); if (p.startsWith(l)) { - String result = p.substring(l.length()); - if (result.startsWith(File.separator)) { - result = result.substring(File.separator.length()); - } - return result; + return p.substring(l.length()); } else { return p; } diff --git a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java index ad0fe140b..df7425356 100644 --- a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java @@ -404,6 +404,8 @@ public class FileUtilsTest extends TestCase { new File("c:\\foo\\bar"))); assertEquals(fu.normalize("/bar").getAbsolutePath(), fu.removeLeadingPath(new File("/foo"), new File("/bar"))); + assertEquals(fu.normalize("/foobar").getAbsolutePath(), + fu.removeLeadingPath(new File("/foo"), new File("/foobar"))); } /**