From 5addfa6319faeea99afb07ff361f6187be85806e Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 3 Jul 2018 09:44:50 +0200 Subject: [PATCH] use getParent in isLeadingPath rather than string comparisons --- .../org/apache/tools/ant/util/FileUtils.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index 900b65b51..03b8d81b9 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -1227,17 +1227,15 @@ public class FileUtils { if (!resolveSymlinks) { return isLeadingPath(leading, path); } - String l = leading.getCanonicalPath(); - String p = path.getCanonicalPath(); - if (l.equals(p)) { - return true; - } - // ensure that l ends with a / - // so we never think /foo was a parent directory of /foobar - if (!l.endsWith(File.separator)) { - l += File.separator; - } - return p.startsWith(l); + final File l = leading.getCanonicalFile(); + File p = path.getCanonicalFile(); + do { + if (l.equals(p)) { + return true; + } + p = p.getParentFile(); + } while (p != null); + return false; } /**