--- old/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java 2016-06-17 10:53:12.000000000 +0100 +++ new/src/java.base/windows/classes/sun/nio/fs/WindowsPath.java 2016-06-17 10:53:12.000000000 +0100 @@ -243,13 +243,13 @@ // relative to default directory String remaining = path.substring(root.length()); String defaultDirectory = getFileSystem().defaultDirectory(); - String result; - if (defaultDirectory.endsWith("\\")) { - result = defaultDirectory + remaining; + if (remaining.length() == 0) { + return defaultDirectory; + } else if (defaultDirectory.endsWith("\\")) { + return defaultDirectory + remaining; } else { - result = defaultDirectory + "\\" + remaining; + return defaultDirectory + "\\" + remaining; } - return result; } else { // relative to some other drive String wd; @@ -412,9 +412,11 @@ } // append remaining names in child - for (int j=i; j %s", first, path); @@ -87,6 +88,14 @@ return this; } + PathOps hasRoot() { + out.println("check has root"); + checkPath(); + if (path.getRoot() == null) + fail(); + return this; + } + PathOps parent(String expected) { out.println("check parent"); checkPath(); @@ -147,6 +156,11 @@ return this; } + PathOps makeAbsolute() { + this.path = path.toAbsolutePath(); + return this; + } + PathOps absolute() { out.println("check path is absolute"); checkPath(); @@ -209,6 +223,11 @@ return new PathOps(first, more); } + static PathOps test(Path path) { + return new PathOps(path.toString()); + } + + // -- PathOpss -- static void header(String s) { @@ -219,6 +238,7 @@ static void doWindowsTests() { header("Windows specific tests"); + Path cwd = Paths.get("").toAbsolutePath(); // construction test("C:\\") @@ -417,6 +437,52 @@ test("C:\\abc").absolute(); test("\\\\server\\share\\").absolute(); test("").notAbsolute(); + test(cwd).absolute(); + + // toAbsolutePath + test("") + .makeAbsolute() + .absolute() + .hasRoot() + .string(cwd.toString()); + test(".") + .makeAbsolute() + .absolute() + .hasRoot() + .string(cwd.toString() + "\\."); + test("foo") + .makeAbsolute() + .absolute() + .hasRoot() + .string(cwd.toString() + "\\foo"); + + String rootAsString = cwd.getRoot().toString(); + if (rootAsString.length() == 3 + && rootAsString.charAt(1) == ':' + && rootAsString.charAt(2) == '\\') { + Path root = Paths.get(rootAsString.substring(0, 2)); + + // C: + test(root) + .makeAbsolute() + .absolute() + .hasRoot() + .string(cwd.toString()); + + // C:. + test(root + ".") + .makeAbsolute() + .absolute() + .hasRoot() + .string(cwd.toString() + "\\."); + + // C:foo + test(root + "foo") + .makeAbsolute() + .absolute() + .hasRoot() + .string(cwd.toString() + "\\foo"); + } // resolve test("C:\\") @@ -506,19 +572,29 @@ .resolveSibling("C:\\", "C:\\"); // relativize + test("foo") + .relativize("foo", "") + .relativize("bar", "..\\bar") + .relativize("..", "..\\..") + .relativize("", ".."); test("foo\\bar") .relativize("foo\\bar", "") - .relativize("foo", ".."); + .relativize("foo", "..") + .relativize("gus", "..\\..\\gus") + .relativize("..", "..\\..\\..") + .relativize("", "..\\.."); test("C:\\a\\b\\c") .relativize("C:\\a", "..\\..") - .relativize("C:\\a\\b\\c", ""); + .relativize("C:\\a\\b\\c", "") + .relativize("C:\\x", "..\\..\\..\\x"); test("\\\\server\\share\\foo") .relativize("\\\\server\\share\\bar", "..\\bar") .relativize("\\\\server\\share\\foo", ""); test("") - .relativize("", "") .relativize("a", "a") - .relativize("a\\b\\c", "a\\b\\c"); + .relativize("a\\b\\c", "a\\b\\c") + .relativize("..", "..") + .relativize("", ""); // normalize test("C:\\") @@ -672,6 +748,7 @@ static void doUnixTests() { header("Unix specific tests"); + Path cwd = Paths.get("").toAbsolutePath(); // construction test("/") @@ -840,7 +917,22 @@ .notAbsolute(); test("") .notAbsolute(); + test(cwd) + .absolute(); + // toAbsolutePath + test("/") + .makeAbsolute() + .absolute(); + test("/tmp") + .makeAbsolute() + .absolute(); + test("tmp") + .makeAbsolute() + .absolute(); + test("") + .makeAbsolute() + .absolute(); // resolve test("/tmp")