6457406: javadoc doesn't handle <a href='http://...'> properly in producing index pages
Reviewed-by: jjg, bpatel, ksrini
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Fri Feb 21 10:35:19 2014 +0100
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Fri Feb 21 15:14:09 2014 +0400
@@ -1713,9 +1713,13 @@
//might be missing '>' character because the href has an inline tag.
break;
}
- if (textBuff.substring(begin, end).contains("\"")){
- begin = textBuff.indexOf("\"", begin) + 1;
- end = textBuff.indexOf("\"", begin +1);
+
+ String quote = textBuff.substring(begin, end);
+ quote = quote.contains("\"") ? "\"" :
+ quote.contains("\'") ? "\'" : null;
+ if (quote != null) {
+ begin = textBuff.indexOf(quote, begin) + 1;
+ end = textBuff.indexOf(quote, begin +1);
if (begin == 0 || end == -1){
//Link is missing a quote.
break;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testSingleQuotedLink/TestSingleQuotedLink.java Fri Feb 21 15:14:09 2014 +0400
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6457406
+ * @summary Verify that a link in single quotes copied to the class-use page as is.
+ * @author Yuri Nesterenko
+ * @library ../lib/
+ * @build JavadocTester TestSingleQuotedLink
+ * @run main TestSingleQuotedLink
+ */
+public class TestSingleQuotedLink extends JavadocTester {
+
+ private static final String BUG_ID = "6457406";
+ // We are testing the redirection algorithm with a known scenario when a writer is not forced to ignore it: "-use".
+ private static final String[][] TEST = {
+ {BUG_ID + FS + "pkg1" + FS + "class-use" + FS + "C1.html",
+ "<a href=\'http://download.oracle.com/javase/8/docs/technotes/guides/indexC2.html\'>"
+ }
+ };
+ private static final String[][] NEGATED_TEST = {
+ {BUG_ID + FS + "pkg1" + FS + "class-use" + FS + "C1.html",
+ "pkg1/\'http://download.oracle.com/javase/8/docs/technotes/guides/indexC2.html\'>"
+ }
+ };
+ private static final String[] ARGS =
+ new String[]{
+ "-d", BUG_ID, "-sourcepath", SRC_DIR, "-use", "pkg1"
+ };
+
+ /**
+ * The entry point of the test.
+ * @param args the array of command line arguments.
+ */
+ public static void main(String[] args) {
+ TestSingleQuotedLink tester = new TestSingleQuotedLink();
+ run(tester, ARGS, TEST, NEGATED_TEST);
+ tester.printSummary();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getBugId() {
+ return BUG_ID;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getBugName() {
+ return getClass().getName();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testSingleQuotedLink/pkg1/C1.java Fri Feb 21 15:14:09 2014 +0400
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg1;
+
+/**
+ * Class 1. This is a test.
+ */
+public class C1 {}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testSingleQuotedLink/pkg1/C2.java Fri Feb 21 15:14:09 2014 +0400
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package pkg1;
+
+/**
+ * Class 2 refers to <a href='http://download.oracle.com/javase/8/docs/technotes/guides/indexC2.html'>Here</a>.
+ * This is a single quoted link.
+ */
+public class C2 extends C1 {}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testSingleQuotedLink/pkg1/package.html Fri Feb 21 15:14:09 2014 +0400
@@ -0,0 +1,14 @@
+<html>
+<head>
+<title>javax.management package</title>
+</head>
+<body bgcolor="white">
+ This is a test.
+ <p id="spec">
+ <a href='http://download.oracle.com/javase/8/docs/technotes/guides/indexdocument.html'>
+ Another Test document 2.</a> Single quotes also but as of now, package-summary writer excluded from redirection algorithm.
+
+ @since 1.5
+
+</body>
+</html>