Fri, 05 Oct 2012 14:21:09 -0700
4696488: javadoc doesn't handle UNC paths for destination directory
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Fri Oct 05 14:16:32 2012 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Fri Oct 05 14:21:09 2012 -0700 1.3 @@ -488,17 +488,18 @@ 1.4 } 1.5 1.6 /** 1.7 - * Add a traliling file separator, if not found or strip off extra trailing 1.8 - * file separators if any. 1.9 + * Add a trailing file separator, if not found. Remove superfluous 1.10 + * file separators if any. Preserve the front double file separator for 1.11 + * UNC paths. 1.12 * 1.13 * @param path Path under consideration. 1.14 * @return String Properly constructed path string. 1.15 */ 1.16 - String addTrailingFileSep(String path) { 1.17 + public static String addTrailingFileSep(String path) { 1.18 String fs = System.getProperty("file.separator"); 1.19 String dblfs = fs + fs; 1.20 int indexDblfs; 1.21 - while ((indexDblfs = path.indexOf(dblfs)) >= 0) { 1.22 + while ((indexDblfs = path.indexOf(dblfs, 1)) >= 0) { 1.23 path = path.substring(0, indexDblfs) + 1.24 path.substring(indexDblfs + fs.length()); 1.25 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javadoc/T4696488.java Fri Oct 05 14:21:09 2012 -0700 2.3 @@ -0,0 +1,56 @@ 2.4 +/* 2.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +import com.sun.tools.doclets.internal.toolkit.Configuration; 2.28 + 2.29 +/** 2.30 + * @test 2.31 + * @bug 4696488 2.32 + * @summary javadoc doesn't handle UNC paths for destination directory 2.33 + * @author Jesse Glick 2.34 + * @run main T4696488 T4696488.java 2.35 + */ 2.36 +public class T4696488 { 2.37 + 2.38 + public static void main(String... args) { 2.39 + System.setProperty("file.separator", "/"); 2.40 + assertAddTrailingFileSep("/path/to/dir", "/path/to/dir/"); 2.41 + assertAddTrailingFileSep("/path/to/dir/", "/path/to/dir/"); 2.42 + assertAddTrailingFileSep("/path/to/dir//", "/path/to/dir/"); 2.43 + System.setProperty("file.separator", "\\"); 2.44 + assertAddTrailingFileSep("C:\\path\\to\\dir", "C:\\path\\to\\dir\\"); 2.45 + assertAddTrailingFileSep("C:\\path\\to\\dir\\", "C:\\path\\to\\dir\\"); 2.46 + assertAddTrailingFileSep("C:\\path\\to\\dir\\\\", "C:\\path\\to\\dir\\"); 2.47 + assertAddTrailingFileSep("\\\\server\\share\\path\\to\\dir", "\\\\server\\share\\path\\to\\dir\\"); 2.48 + assertAddTrailingFileSep("\\\\server\\share\\path\\to\\dir\\", "\\\\server\\share\\path\\to\\dir\\"); 2.49 + assertAddTrailingFileSep("\\\\server\\share\\path\\to\\dir\\\\", "\\\\server\\share\\path\\to\\dir\\"); 2.50 + } 2.51 + 2.52 + private static void assertAddTrailingFileSep(String input, String expectedOutput) { 2.53 + String output = Configuration.addTrailingFileSep(input); 2.54 + if (!expectedOutput.equals(output)) { 2.55 + throw new Error("expected " + expectedOutput + " but was " + output); 2.56 + } 2.57 + } 2.58 + 2.59 +}