From 869b123c0437855adde003d242e4e084e8b35731 Mon Sep 17 00:00:00 2001 From: "Jesse N. Glick" Date: Thu, 17 Aug 2006 20:23:44 +0000 Subject: [PATCH] #40281: "Cannot resolve path" error thrown gratuitously. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@432379 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++++ .../org/apache/tools/ant/util/FileUtils.java | 3 ++- .../apache/tools/ant/util/FileUtilsTest.java | 18 ++++++------------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 68384b6f0..a50c9d627 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -102,6 +102,10 @@ Changes that could break older environments: Fixed bugs: ----------- +* The build could be halted if a file path contained more ".." components than + the actual depth of the preceding path. Now such paths are left alone (meaning + they will likely be treated as nonexistent files). Bugzilla Report 40281. + * Converting a to a string was broken. Bugzilla Report 39683. * Manifests have improved line length handling, taking care of encoding. diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index c7165675a..ced52a115 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -674,7 +674,8 @@ public class FileUtils { continue; } else if ("..".equals(thisToken)) { if (s.size() < 2) { - throw new BuildException("Cannot resolve path " + path); + // Cannot resolve it, so skip it. + return new File(path); } s.pop(); } else { // plain component diff --git a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java index c154a69c6..cc7b1699f 100644 --- a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java @@ -193,12 +193,9 @@ public class FileUtilsTest extends TestCase { assertEquals(localize("/1/2/3/4"), FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "..\\../5/..\\./2/./3/6\\../4").getPath()); - try { - FILE_UTILS.resolveFile(new File(localize("/1")), "../../b"); - fail("successfully crawled beyond the filesystem root"); - } catch (BuildException e) { - // Expected Exception caught - } + assertEquals("meaningless result but no exception", + new File(localize("/1/../../b")), + FILE_UTILS.resolveFile(new File(localize("/1")), "../../b")); } @@ -315,12 +312,9 @@ public class FileUtilsTest extends TestCase { // Expected exception caught } - try { - FILE_UTILS.normalize(localize("/1/../../b")); - fail("successfully crawled beyond the filesystem root"); - } catch (BuildException e) { - // Expected exception caught - } + assertEquals("will not go outside FS root (but will not throw an exception either)", + new File(localize("/1/../../b")), + FILE_UTILS.normalize(localize("/1/../../b"))); } /**