diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 083ea4a0b..fd6e0d1bb 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -453,9 +453,10 @@ public class Project { } public File resolveFile(String fileName) { + fileName = fileName.replace('/', File.separatorChar).replace('\\', File.separatorChar); + // deal with absolute files - if (fileName.startsWith("/")) return new File( fileName ); - if (fileName.startsWith(System.getProperty("file.separator"))) + if (fileName.startsWith(File.separator)) return new File( fileName ); // Eliminate consecutive slashes after the drive spec @@ -488,7 +489,7 @@ public class Project { } File file = new File(baseDir.getAbsolutePath()); - StringTokenizer tok = new StringTokenizer(fileName, "/", false); + StringTokenizer tok = new StringTokenizer(fileName, File.separator, false); while (tok.hasMoreTokens()) { String part = tok.nextToken(); if (part.equals("..")) { diff --git a/src/main/org/apache/tools/ant/types/Commandline.java b/src/main/org/apache/tools/ant/types/Commandline.java index 50d0c7186..753aec0c6 100644 --- a/src/main/org/apache/tools/ant/types/Commandline.java +++ b/src/main/org/apache/tools/ant/types/Commandline.java @@ -265,7 +265,7 @@ public class Commandline implements Cloneable { final int inQuote = 1; final int inDoubleQuote = 2; int state = normal; - StringTokenizer tok = new StringTokenizer(to_process, "\\\"\' ", true); + StringTokenizer tok = new StringTokenizer(to_process, "\"\' ", true); Vector v = new Vector(); StringBuffer current = new StringBuffer(); @@ -296,21 +296,6 @@ public class Commandline implements Cloneable { v.addElement(current.toString()); current.setLength(0); } - } else if ("\\".equals(nextTok)) { - if (tok.hasMoreTokens()) { - String escapedToken = tok.nextToken(); - char escapedChar = escapedToken.charAt(0); - if (escapedChar == '\\' || escapedChar == '\'' || - escapedChar == '\"') { - current.append(escapedToken); - } - else { - current.append("\\" + escapedToken); - } - } else { - // just add the backslash - current.append("\\"); - } } else { current.append(nextTok); } diff --git a/src/testcases/org/apache/tools/ant/types/CommandlineTest.java b/src/testcases/org/apache/tools/ant/types/CommandlineTest.java index e6ae7d3af..ff2119f7e 100644 --- a/src/testcases/org/apache/tools/ant/types/CommandlineTest.java +++ b/src/testcases/org/apache/tools/ant/types/CommandlineTest.java @@ -111,17 +111,14 @@ public class CommandlineTest extends TestCase { assertEquals("Single quotes stripped, double quote included", "2\"3", s[1]); - s = Commandline.translateCommandline("1 2\\\'3 4"); - assertEquals("Case with quoted single quote", 3, s.length); - assertEquals("single quote included", "2\'3", s[1]); - - s = Commandline.translateCommandline("1 2\\\"3 4"); - assertEquals("Case with quoted double quote", 3, s.length); - assertEquals("double quote included", "2\"3", s[1]); + // \ doesn't have a special meaning anymore - this is different from + // what the Unix sh does but causes a lot of problems on DOS + // based platforms otherwise + s = Commandline.translateCommandline("1 2\\ 3 4"); + assertEquals("case with quotes whitespace", 4, s.length); + assertEquals("Single quotes stripped, double quote included", "2\\", + s[1]); - s = Commandline.translateCommandline("1 2\\\\3 4"); - assertEquals("Case with quoted backslash", 3, s.length); - assertEquals("backslash included", "2\\3", s[1]); // now to the expected failures diff --git a/src/testcases/org/apache/tools/ant/types/PathTest.java b/src/testcases/org/apache/tools/ant/types/PathTest.java index b036f86b2..a3b28aada 100644 --- a/src/testcases/org/apache/tools/ant/types/PathTest.java +++ b/src/testcases/org/apache/tools/ant/types/PathTest.java @@ -124,7 +124,8 @@ public class PathTest extends TestCase { l = p.list(); if (isUnixStyle) { assertEquals("no drives on Unix", 2, l.length); - assertEquals("c", l[0]); + assert("c resolved relative to project\'s basedir", + l[0].endsWith("/c")); assertEquals("/test", l[1]); } else { assertEquals("drives on DOS", 1, l.length); @@ -135,7 +136,8 @@ public class PathTest extends TestCase { l = p.list(); if (isUnixStyle) { assertEquals("no drives on Unix", 2, l.length); - assertEquals("c", l[0]); + assert("c resolved relative to project\'s basedir", + l[0].endsWith("/c")); assertEquals("/test", l[1]); } else { assertEquals("drives on DOS", 1, l.length);