Browse Source

#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
master
Jesse N. Glick 19 years ago
parent
commit
869b123c04
3 changed files with 12 additions and 13 deletions
  1. +4
    -0
      WHATSNEW
  2. +2
    -1
      src/main/org/apache/tools/ant/util/FileUtils.java
  3. +6
    -12
      src/testcases/org/apache/tools/ant/util/FileUtilsTest.java

+ 4
- 0
WHATSNEW View File

@@ -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 <dirset> to a string was broken. Bugzilla Report 39683.

* Manifests have improved line length handling, taking care of encoding.


+ 2
- 1
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -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


+ 6
- 12
src/testcases/org/apache/tools/ant/util/FileUtilsTest.java View File

@@ -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")));
}

/**


Loading…
Cancel
Save