From 4c83562c6c9f681cdcd17c86f5e3c68c910dd5f8 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Tue, 1 Mar 2005 22:59:44 +0000 Subject: [PATCH] On DOS and Netware, filenames beginning with a drive letter and followed by a colon but with no directory separator following the colon are no longer (incorrectly) accepted as absolute pathnames by FileUtils.normalize() and FileUtils.isAbsolutePath(). Netware volumes can still be specified without an intervening separator. UNC pathnames on Windows must include a server and share name, i.e. "\\a\b" to be considered valid absolute paths. FileUtils.resolveFile() promised to return absolute files but did not always do so. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277759 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 14 +- .../org/apache/tools/ant/util/FileUtils.java | 251 +++++++++--------- .../org/apache/tools/ant/ProjectTest.java | 48 +++- .../tools/ant/taskdefs/DirnameTest.java | 4 + .../org/apache/tools/ant/types/PathTest.java | 20 +- .../apache/tools/ant/util/FileUtilsTest.java | 111 +++++--- 6 files changed, 262 insertions(+), 186 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 155382501..c7dfce9da 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -18,8 +18,15 @@ Changes that could break older environments: * The Reference class now has a project field that will get used (if set) in preference to the passed in project, when - dereferencing the reference. - Bugzilla Report 25777. + dereferencing the reference. Bugzilla Report 25777. + +* On DOS and Netware, filenames beginning with a drive letter + and followed by a colon but with no directory separator following + the colon are no longer (incorrectly) accepted as absolute pathnames + by FileUtils.normalize() and FileUtils.isAbsolutePath(). Netware + volumes can still be specified without an intervening separator. + UNC pathnames on Windows must include a server and share name, i.e. + "\\a\b" to be considered valid absolute paths. Fixed bugs: ----------- @@ -47,6 +54,9 @@ Fixed bugs: * Create signjar's helper ExecTask instance directly rather than by typedef discovery mechanisms. Bugzilla report 33433. +* FileUtils.resolveFile() promised to return absolute files but + did not always do so. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index b47a4efd6..01d3f24ae 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -664,71 +664,99 @@ public class FileUtils { /** * Interpret the filename as a file relative to the given file * unless the filename already represents an absolute filename. + * Differs from new File(file, filename) in that + * the resulting File's path will always be a normalized, + * absolute pathname. Also, if it is determined that + * filename is context-relative, file + * will be discarded and the reference will be resolved using + * available context/state information about the filesystem. * * @param file the "reference" file for relative paths. This * instance must be an absolute file and must not contain * "./" or "../" sequences (same for \ instead * of /). If it is null, this call is equivalent to - * new java.io.File(filename). + * new java.io.File(filename).getAbsoluteFile(). * * @param filename a file name. * - * @return an absolute file that doesn't contain "./" or - * "../" sequences and uses the correct separator for - * the current platform. + * @return an absolute file. + * @throws java.lang.NullPointerException if filename is null. */ public File resolveFile(File file, String filename) { - filename = filename.replace('/', File.separatorChar) - .replace('\\', File.separatorChar); - - // deal with absolute files - if (isAbsolutePath(filename)) { - return normalize(filename); - } - if (file == null) { - return new File(filename); - } - File helpFile = new File(file.getAbsolutePath()); - StringTokenizer tok = new StringTokenizer(filename, File.separator); - while (tok.hasMoreTokens()) { - String part = tok.nextToken(); - if (part.equals("..")) { - helpFile = helpFile.getParentFile(); - if (helpFile == null) { - String msg = "The file or path you specified (" - + filename + ") is invalid relative to " - + file.getPath(); - throw new BuildException(msg); + if (!isAbsolutePath(filename)) { + char sep = File.separatorChar; + filename = filename.replace('/', sep).replace('\\', sep); + if (isContextRelativePath(filename)) { + file = null; + // on cygwin, our current directory can be a UNC; + // assume user.dir is absolute or all hell breaks loose... + String udir = System.getProperty("user.dir"); + if (filename.charAt(0) == sep && udir.charAt(0) == sep) { + filename = dissect(udir)[0] + filename.substring(1); } - } else if (part.equals(".")) { - // Do nothing here - } else { - helpFile = new File(helpFile, part); } + filename = new File(file, filename).getAbsolutePath(); } - return new File(helpFile.getAbsolutePath()); + return normalize(filename); + } + + /** + * On DOS and NetWare, the evaluation of certain file + * specifications is context-dependent. These are filenames + * beginning with a single separator (relative to current root directory) + * and filenames with a drive specification and no intervening separator + * (relative to current directory of the specified root). + * @param filename the filename to evaluate. + * @return true if the filename is relative to system context. + * @throws java.lang.NullPointerException if filename is null. + * @since Ant 1.7 + */ + public static boolean isContextRelativePath(String filename) { + if (!(onDos || onNetWare) || filename.length() == 0) { + return false; + } + char sep = File.separatorChar; + filename = filename.replace('/', sep).replace('\\', sep); + char c = filename.charAt(0); + int len = filename.length(); + return (c == sep && (len == 1 || filename.charAt(1) != sep)) + || (Character.isLetter(c) && len > 1 + && filename.indexOf(':') == 1 + && (len == 2 || filename.charAt(2) != sep)); } /** * Verifies that the specified filename represents an absolute path. + * Differs from new java.io.File("filename").isAbsolute() in that a path + * beginning with a double file separator--signifying a Windows UNC--must + * at minimum match "\\a\b" to be considered an absolute path. * @param filename the filename to be checked. * @return true if the filename represents an absolute path. + * @throws java.lang.NullPointerException if filename is null. + * @since Ant 1.6.3 */ public static boolean isAbsolutePath(String filename) { - if (filename.startsWith(File.separator)) { - // common for all os - return true; + int len = filename.length(); + if (len == 0) { + return false; } - if (onDos && filename.length() >= 2 - && Character.isLetter(filename.charAt(0)) - && filename.charAt(1) == ':') { - // Actually on windows the : must be followed by a \ for - // the path to be absolute, else the path is relative - // to the current working directory on that drive. - // (Every drive may have another current working directory) - return true; + char sep = File.separatorChar; + filename = filename.replace('/', sep).replace('\\', sep); + char c = filename.charAt(0); + if (!(onDos || onNetWare)) { + return (c == sep); } - return (onNetWare && filename.indexOf(":") > -1); + if (c == sep) { + if (!(onDos && len > 4 && filename.charAt(1) == sep)) { + return false; + } + int nextsep = filename.indexOf(sep, 2); + return nextsep > 2 && nextsep + 1 < len; + } + int colon = filename.indexOf(':'); + return (Character.isLetter(c) && colon == 1 + && filename.length() > 2 && filename.charAt(2) == sep) + || (onNetWare && colon > 0); } /** @@ -748,78 +776,23 @@ public class FileUtils { * @param path the path to be normalized. * @return the normalized version of the path. * - * @throws java.lang.NullPointerException if the file path is - * equal to null. + * @throws java.lang.NullPointerException if path is null. */ - public File normalize(String path) { - String orig = path; - - path = path.replace('/', File.separatorChar) - .replace('\\', File.separatorChar); - - // make sure we are dealing with an absolute path - int colon = path.indexOf(":"); - - if (!isAbsolutePath(path)) { - String msg = path + " is not an absolute path"; - throw new BuildException(msg); - } - boolean dosWithDrive = false; - String root = null; - // Eliminate consecutive slashes after the drive spec - if ((onDos && path.length() >= 2 - && Character.isLetter(path.charAt(0)) - && path.charAt(1) == ':') - || (onNetWare && colon > -1)) { - - dosWithDrive = true; - - char[] ca = path.replace('/', '\\').toCharArray(); - StringBuffer sbRoot = new StringBuffer(); - for (int i = 0; i < colon; i++) { - sbRoot.append(Character.toUpperCase(ca[i])); - } - sbRoot.append(':'); - if (colon + 1 < path.length()) { - sbRoot.append(File.separatorChar); - } - root = sbRoot.toString(); - - // Eliminate consecutive slashes after the drive spec - StringBuffer sbPath = new StringBuffer(); - for (int i = colon + 1; i < ca.length; i++) { - if ((ca[i] != '\\') - || (ca[i] == '\\' && ca[i - 1] != '\\')) { - sbPath.append(ca[i]); - } - } - path = sbPath.toString().replace('\\', File.separatorChar); - } else { - if (path.length() == 1) { - root = File.separator; - path = ""; - } else if (path.charAt(1) == File.separatorChar) { - // UNC drive - root = File.separator + File.separator; - path = path.substring(2); - } else { - root = File.separator; - path = path.substring(1); - } - } + public File normalize(final String path) { Stack s = new Stack(); - s.push(root); - StringTokenizer tok = new StringTokenizer(path, File.separator); + String[] dissect = dissect(path); + s.push(dissect[0]); + + StringTokenizer tok = new StringTokenizer(dissect[1], File.separator); while (tok.hasMoreTokens()) { String thisToken = tok.nextToken(); if (".".equals(thisToken)) { continue; } else if ("..".equals(thisToken)) { if (s.size() < 2) { - throw new BuildException("Cannot resolve path " + orig); - } else { - s.pop(); + throw new BuildException("Cannot resolve path " + path); } + s.pop(); } else { // plain component s.push(thisToken); } @@ -833,11 +806,53 @@ public class FileUtils { } sb.append(s.elementAt(i)); } - path = sb.toString(); - if (dosWithDrive) { - path = path.replace('/', '\\'); + return new File(sb.toString()); + } + + /** + * Dissect the specified absolute path. + * @param path the path to dissect. + * @return String[] {root, remaining path}. + * @throws java.lang.NullPointerException if path is null. + */ + public String[] dissect(String path) { + char sep = File.separatorChar; + path = path.replace('/', sep).replace('\\', sep); + + // make sure we are dealing with an absolute path + if (!isAbsolutePath(path)) { + throw new BuildException(path + " is not an absolute path"); + } + String root = null; + int colon = path.indexOf(':'); + if (colon > 0 && (onDos || onNetWare)) { + + int next = colon + 1; + root = path.substring(0, next).toUpperCase(); + char[] ca = path.toCharArray(); + root += sep; + //remove the initial separator; the root has it. + next = (ca[next] == sep) ? next + 1 : next; + + StringBuffer sbPath = new StringBuffer(); + // Eliminate consecutive slashes after the drive spec: + for (int i = next; i < ca.length; i++) { + if (ca[i] != sep || ca[i - 1] != sep) { + sbPath.append(ca[i]); + } + } + path = sbPath.toString(); + } else if (path.length() > 1 && path.charAt(1) == sep) { + // UNC drive + int nextsep = path.indexOf(sep, 2); + nextsep = path.indexOf(sep, nextsep + 1); + root = (nextsep > 2) ? path.substring(0, nextsep + 1) : path; + path = path.substring(root.length()); + } else { + root = File.separator; + path = path.substring(1); } - return new File(path); + return new String[] {root, path}; } /** @@ -1213,22 +1228,16 @@ public class FileUtils { * @since Ant 1.6 */ public String toURI(String path) { - boolean isDir = (new File(path)).isDirectory(); + boolean isDir = new File(path).isDirectory(); StringBuffer sb = new StringBuffer("file:"); - // catch exception if normalize thinks this is not an absolute path - try { - path = normalize(path).getAbsolutePath(); - sb.append("//"); - // add an extra slash for filesystems with drive-specifiers - if (!path.startsWith(File.separator)) { - sb.append("/"); - } - } catch (BuildException e) { - // relative path + path = resolveFile(null, path).getPath(); + sb.append("//"); + // add an extra slash for filesystems with drive-specifiers + if (!path.startsWith(File.separator)) { + sb.append("/"); } - path = path.replace('\\', '/'); CharacterIterator iter = new StringCharacterIterator(path); diff --git a/src/testcases/org/apache/tools/ant/ProjectTest.java b/src/testcases/org/apache/tools/ant/ProjectTest.java index 3f60f935b..8524f3f35 100644 --- a/src/testcases/org/apache/tools/ant/ProjectTest.java +++ b/src/testcases/org/apache/tools/ant/ProjectTest.java @@ -48,7 +48,7 @@ public class ProjectTest extends TestCase { public void setUp() { p = new Project(); p.init(); - root = new File(File.separator).getAbsolutePath(); + root = new File(File.separator).getAbsolutePath().toUpperCase(); mbl = new MockBuildListener(p); } @@ -67,15 +67,11 @@ public class ProjectTest extends TestCase { * This test has been a starting point for moving the code to FileUtils. */ public void testResolveFile() { - /* - * Start with simple absolute file names. - */ - assertEquals(File.separator, - p.resolveFile("/", null).getPath()); - assertEquals(File.separator, - p.resolveFile("\\", null).getPath()); - if (Os.isFamily("netware") || Os.isFamily("dos")) { + assertEqualsIgnoreDriveCase(localize(File.separator), + p.resolveFile("/", null).getPath()); + assertEqualsIgnoreDriveCase(localize(File.separator), + p.resolveFile("\\", null).getPath()); /* * throw in drive letters */ @@ -97,19 +93,27 @@ public class ProjectTest extends TestCase { assertEquals(driveSpec + "\\", p.resolveFile(driveSpec + "\\\\\\\\\\\\", null).getPath()); } else { + /* + * Start with simple absolute file names. + */ + assertEquals(File.separator, + p.resolveFile("/", null).getPath()); + assertEquals(File.separator, + p.resolveFile("\\", null).getPath()); /* * drive letters are not used, just to be considered as normal * part of a name */ String driveSpec = "C:"; - assertEquals(driveSpec, + String udir = System.getProperty("user.dir") + File.separatorChar; + assertEquals(udir + driveSpec, p.resolveFile(driveSpec + "/", null).getPath()); - assertEquals(driveSpec, + assertEquals(udir + driveSpec, p.resolveFile(driveSpec + "\\", null).getPath()); String driveSpecLower = "c:"; - assertEquals(driveSpecLower, + assertEquals(udir + driveSpecLower, p.resolveFile(driveSpecLower + "/", null).getPath()); - assertEquals(driveSpecLower, + assertEquals(udir + driveSpecLower, p.resolveFile(driveSpecLower + "\\", null).getPath()); } /* @@ -142,6 +146,24 @@ public class ProjectTest extends TestCase { return path.replace('\\', File.separatorChar).replace('/', File.separatorChar); } + /** + * convenience method + * the drive letter is in lower case under cygwin + * calling this method allows tests where FileUtils.normalize + * is called via resolveFile to pass under cygwin + */ + private void assertEqualsIgnoreDriveCase(String s1, String s2) { + if ((Os.isFamily("dos") || Os.isFamily("netware")) + && s1.length() >= 1 && s2.length() >= 1) { + StringBuffer sb1 = new StringBuffer(s1); + StringBuffer sb2 = new StringBuffer(s2); + sb1.setCharAt(0, Character.toUpperCase(s1.charAt(0))); + sb2.setCharAt(0, Character.toUpperCase(s2.charAt(0))); + assertEquals(sb1.toString(), sb2.toString()); + } else { + assertEquals(s1, s2); + } + } private void assertTaskDefFails(final Class taskClass, final String message) { diff --git a/src/testcases/org/apache/tools/ant/taskdefs/DirnameTest.java b/src/testcases/org/apache/tools/ant/taskdefs/DirnameTest.java index bedb038ce..b95243843 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/DirnameTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/DirnameTest.java @@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs; import java.io.File; import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.taskdefs.condition.Os; /** */ @@ -45,6 +46,9 @@ public class DirnameTest extends BuildFileTest { } public void test4() { + if (Os.isFamily("netware") || Os.isFamily("dos")) { + return; + } executeTarget("test4"); String filesep = System.getProperty("file.separator"); String expected = filesep + "usr" + filesep + "local"; diff --git a/src/testcases/org/apache/tools/ant/types/PathTest.java b/src/testcases/org/apache/tools/ant/types/PathTest.java index 6e9693b0c..e0d95cc08 100644 --- a/src/testcases/org/apache/tools/ant/types/PathTest.java +++ b/src/testcases/org/apache/tools/ant/types/PathTest.java @@ -60,8 +60,9 @@ public class PathTest extends TestCase { assertEquals("\\a", l[0]); assertEquals("\\b", l[1]); } else { - assertEquals(":\\a", l[0].substring(1)); - assertEquals(":\\b", l[1].substring(1)); + String base = new File(File.separator).getAbsolutePath().toUpperCase(); + assertEquals(base + "a", l[0]); + assertEquals(base + "b", l[1]); } } @@ -99,8 +100,9 @@ public class PathTest extends TestCase { assertEquals("\\a", l[0]); assertEquals("\\b", l[1]); } else { - assertEquals(":\\a", l[0].substring(1)); - assertEquals(":\\b", l[1].substring(1)); + String base = new File(File.separator).getAbsolutePath().toUpperCase(); + assertEquals(base + "a", l[0]); + assertEquals(base + "b", l[1]); } p = new Path(project, "c:\\test"); @@ -307,9 +309,10 @@ public class PathTest extends TestCase { assertEquals("\\b", l[1]); assertEquals("\\c", l[2]); } else { - assertEquals(":\\a", l[0].substring(1)); - assertEquals(":\\b", l[1].substring(1)); - assertEquals(":\\c", l[2].substring(1)); + String base = new File(File.separator).getAbsolutePath().toUpperCase(); + assertEquals(base + "a", l[0]); + assertEquals(base + "b", l[1]); + assertEquals(base + "c", l[2]); } } @@ -366,7 +369,8 @@ public class PathTest extends TestCase { Path p = new Path(project, "/a:/a"); String[] l = p.list(); assertEquals("1 after construction", 1, l.length); - p.setLocation(new File(File.separatorChar+"a")); + String base = new File(File.separator).getAbsolutePath().toUpperCase(); + p.setLocation(new File(base, "a")); l = p.list(); assertEquals("1 after setLocation", 1, l.length); p.setPath("\\a;/a"); diff --git a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java index 8dbe3df61..a5da6914e 100644 --- a/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java @@ -101,15 +101,19 @@ public class FileUtilsTest extends TestCase { } public void testResolveFile() { - /* - * Start with simple absolute file names. - */ - assertEquals(File.separator, - FILE_UTILS.resolveFile(null, "/").getPath()); - assertEquals(File.separator, - FILE_UTILS.resolveFile(null, "\\").getPath()); - - if (Os.isFamily("dos")) { + if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { + /* + * Start with simple absolute file names. + */ + assertEquals(File.separator, + FILE_UTILS.resolveFile(null, "/").getPath()); + assertEquals(File.separator, + FILE_UTILS.resolveFile(null, "\\").getPath()); + } else { + assertEqualsIgnoreDriveCase(localize(File.separator), + FILE_UTILS.resolveFile(null, "/").getPath()); + assertEqualsIgnoreDriveCase(localize(File.separator), + FILE_UTILS.resolveFile(null, "\\").getPath()); /* * throw in drive letters */ @@ -130,7 +134,8 @@ public class FileUtilsTest extends TestCase { FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath()); assertEquals(driveSpec + "\\", FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath()); - } else if (Os.isFamily("netware")) { + } + if (Os.isFamily("netware")) { /* * throw in NetWare volume names */ @@ -151,19 +156,20 @@ public class FileUtilsTest extends TestCase { FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath()); assertEquals(driveSpec, FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath()); - } else { + } else if (!(Os.isFamily("dos"))) { /* * drive letters must be considered just normal filenames. */ String driveSpec = "C:"; - assertEquals(driveSpec, + String udir = System.getProperty("user.dir"); + assertEquals(udir + File.separator + driveSpec, FILE_UTILS.resolveFile(null, driveSpec + "/").getPath()); - assertEquals(driveSpec, + assertEquals(udir + File.separator + driveSpec, FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath()); String driveSpecLower = "c:"; - assertEquals(driveSpecLower, + assertEquals(udir + File.separator + driveSpecLower, FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath()); - assertEquals(driveSpecLower, + assertEquals(udir + File.separator + driveSpecLower, FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath()); } @@ -197,21 +203,37 @@ public class FileUtilsTest extends TestCase { } public void testNormalize() { - /* - * Start with simple absolute file names. - */ - assertEquals(File.separator, - FILE_UTILS.normalize("/").getPath()); - assertEquals(File.separator, - FILE_UTILS.normalize("\\").getPath()); + if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { + /* + * Start with simple absolute file names. + */ + assertEquals(File.separator, + FILE_UTILS.normalize("/").getPath()); + assertEquals(File.separator, + FILE_UTILS.normalize("\\").getPath()); + } else { + try { + FILE_UTILS.normalize("/").getPath(); + fail("normalized \"/\" on dos or netware"); + } catch (Exception e) { + } + try { + FILE_UTILS.normalize("\\").getPath(); + fail("normalized \"\\\" on dos or netware"); + } catch (Exception e) { + } + } if (Os.isFamily("dos")) { /* * throw in drive letters */ String driveSpec = "C:"; - assertEquals(driveSpec, - FILE_UTILS.normalize(driveSpec).getPath()); + try { + FILE_UTILS.normalize(driveSpec).getPath(); + fail(driveSpec + " is not an absolute path"); + } catch (Exception e) { + } assertEquals(driveSpec + "\\", FILE_UTILS.normalize(driveSpec + "/").getPath()); assertEquals(driveSpec + "\\", @@ -313,7 +335,7 @@ public class FileUtilsTest extends TestCase { } File f = FILE_UTILS.resolveFile(null, "a"); - assertEquals(f, new File("a")); + assertEquals(f, new File("a").getAbsoluteFile()); } /** @@ -390,10 +412,12 @@ public class FileUtilsTest extends TestCase { new File("c:\\foo\\bar"))); assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"))); - assertEqualsIgnoreDriveCase(FILE_UTILS.normalize("/bar").getAbsolutePath(), - FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/bar"))); - assertEqualsIgnoreDriveCase(FILE_UTILS.normalize("/foobar").getAbsolutePath(), - FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/foobar"))); + if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { + assertEquals(FILE_UTILS.normalize("/bar").getAbsolutePath(), + FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/bar"))); + assertEquals(FILE_UTILS.normalize("/foobar").getAbsolutePath(), + FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/foobar"))); + } // bugzilla report 19979 assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"), new File("/foo/bar"))); @@ -419,8 +443,9 @@ public class FileUtilsTest extends TestCase { */ public void testToURI() { String dosRoot = null; - if (Os.isFamily("dos")) { - dosRoot = System.getProperty("user.dir").charAt(0) + ":/"; + if (Os.isFamily("dos") || Os.isFamily("netware")) { + dosRoot = Character.toUpperCase( + System.getProperty("user.dir").charAt(0)) + ":/"; } else { @@ -457,11 +482,11 @@ public class FileUtilsTest extends TestCase { if (Os.isFamily("dos")) { assertEqualsIgnoreDriveCase("C:\\foo", FILE_UTILS.fromURI("file:///c:/foo")); } - assertEqualsIgnoreDriveCase(localize("/foo"), FILE_UTILS.fromURI("file:///foo")); + assertEqualsIgnoreDriveCase(File.separator + "foo", FILE_UTILS.fromURI("file:///foo")); assertEquals("." + File.separator + "foo", FILE_UTILS.fromURI("file:./foo")); - assertEqualsIgnoreDriveCase(localize("/foo bar"), FILE_UTILS.fromURI("file:///foo%20bar")); - assertEqualsIgnoreDriveCase(localize("/foo#bar"), FILE_UTILS.fromURI("file:///foo%23bar")); + assertEquals(File.separator + "foo bar", FILE_UTILS.fromURI("file:///foo%20bar")); + assertEquals(File.separator + "foo#bar", FILE_UTILS.fromURI("file:///foo%23bar")); } public void testModificationTests() { @@ -493,6 +518,7 @@ public class FileUtilsTest extends TestCase { path = root + path.substring(1); return path.replace('\\', File.separatorChar).replace('/', File.separatorChar); } + /** * convenience method * normalize brings the drive in uppercase @@ -500,14 +526,15 @@ public class FileUtilsTest extends TestCase { * calling this method allows tests where normalize is called to pass under cygwin */ private void assertEqualsIgnoreDriveCase(String s1, String s2) { - if (Os.isFamily("dos") && s1.length()>=1 && s2.length()>=1) { - StringBuffer sb1= new StringBuffer(s1); - StringBuffer sb2= new StringBuffer(s2); - sb1.setCharAt(0,Character.toUpperCase(s1.charAt(0))); - sb2.setCharAt(0,Character.toUpperCase(s2.charAt(0))); - assertEquals(sb1.toString(),sb2.toString()); - } else { - assertEquals(s1,s2); + if ((Os.isFamily("dos") || Os.isFamily("netware")) + && s1.length() > 0 && s2.length() > 0) { + StringBuffer sb1 = new StringBuffer(s1); + StringBuffer sb2 = new StringBuffer(s2); + sb1.setCharAt(0, Character.toUpperCase(s1.charAt(0))); + sb2.setCharAt(0, Character.toUpperCase(s2.charAt(0))); + assertEquals(sb1.toString(), sb2.toString()); + } else { + assertEquals(s1, s2); } } }