# HG changeset patch # User mfang # Date 1380119797 25200 # Node ID 1f40f52b3cccc774ee27e29a2492d7f7a13f4c3a # Parent a3d8494cdba0eb7436399f8f186ff0f75f2c97a9# Parent 9da4f6c300896b4648502379a3407f4837c77a5e Merge diff -r a3d8494cdba0 -r 1f40f52b3ccc langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Tue Sep 24 14:35:24 2013 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTree.java Wed Sep 25 07:36:37 2013 -0700 @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.Writer; import java.util.*; +import java.nio.charset.*; import com.sun.tools.doclets.internal.toolkit.Content; import com.sun.tools.doclets.internal.toolkit.util.*; @@ -164,6 +165,46 @@ } /** + * A set of ASCII URI characters to be left unencoded. + */ + public static BitSet NONENCODING_CHARS = new BitSet(256); + + static { + // alphabetic characters + for (int i = 'a'; i <= 'z'; i++) { + NONENCODING_CHARS.set(i); + } + for (int i = 'A'; i <= 'Z'; i++) { + NONENCODING_CHARS.set(i); + } + // numeric characters + for (int i = '0'; i <= '9'; i++) { + NONENCODING_CHARS.set(i); + } + // Reserved characters as per RFC 3986. These are set of delimiting characters. + String noEnc = ":/?#[]@!$&'()*+,;="; + // Unreserved characters as per RFC 3986 which should not be percent encoded. + noEnc += "-._~"; + for (int i = 0; i < noEnc.length(); i++) { + NONENCODING_CHARS.set(noEnc.charAt(i)); + } + } + + private static String encodeURL(String url) { + byte[] urlBytes = url.getBytes(Charset.forName("UTF-8")); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < urlBytes.length; i++) { + int c = urlBytes[i]; + if (NONENCODING_CHARS.get(c & 0xFF)) { + sb.append((char) c); + } else { + sb.append(String.format("%%%02X", c & 0xFF)); + } + } + return sb.toString(); + } + + /** * Generates an HTML anchor tag. * * @param ref reference url for the anchor tag @@ -172,7 +213,7 @@ */ public static HtmlTree A(String ref, Content body) { HtmlTree htmltree = new HtmlTree(HtmlTag.A, nullCheck(body)); - htmltree.addAttr(HtmlAttr.HREF, ref); + htmltree.addAttr(HtmlAttr.HREF, encodeURL(ref)); return htmltree; } diff -r a3d8494cdba0 -r 1f40f52b3ccc langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java Tue Sep 24 14:35:24 2013 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java Wed Sep 25 07:36:37 2013 -0700 @@ -335,6 +335,12 @@ " if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + DocletConstants.NL + " targetPage = \"undefined\";" + DocletConstants.NL + " function validURL(url) {" + DocletConstants.NL + + " try {" + DocletConstants.NL + + " url = decodeURIComponent(url);" + DocletConstants.NL + + " }" + DocletConstants.NL + + " catch (error) {" + DocletConstants.NL + + " return false;" + DocletConstants.NL + + " }" + DocletConstants.NL + " var pos = url.indexOf(\".html\");" + DocletConstants.NL + " if (pos == -1 || pos != url.length - 5)" + DocletConstants.NL + " return false;" + DocletConstants.NL + @@ -346,7 +352,8 @@ " if ('a' <= ch && ch <= 'z' ||" + DocletConstants.NL + " 'A' <= ch && ch <= 'Z' ||" + DocletConstants.NL + " ch == '$' ||" + DocletConstants.NL + - " ch == '_') {" + DocletConstants.NL + + " ch == '_' ||" + DocletConstants.NL + + " ch.charCodeAt(0) > 127) {" + DocletConstants.NL + " allowNumber = true;" + DocletConstants.NL + " allowSep = true;" + DocletConstants.NL + " } else if ('0' <= ch && ch <= '9'" + DocletConstants.NL + diff -r a3d8494cdba0 -r 1f40f52b3ccc langtools/test/com/sun/javadoc/testHref/TestHref.java --- a/langtools/test/com/sun/javadoc/testHref/TestHref.java Tue Sep 24 14:35:24 2013 -0700 +++ b/langtools/test/com/sun/javadoc/testHref/TestHref.java Wed Sep 25 07:36:37 2013 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 4663254 + * @bug 4663254 8016328 * @summary Verify that spaces do not appear in hrefs and anchors. * @author jamieh * @library ../lib/ @@ -46,11 +46,11 @@ private static final String[][] TEST = { //External link. {BUG_ID + FS + "pkg" + FS + "C1.html", - "href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html?is-external=true#wait(long, int)\"" + "href=\"http://java.sun.com/j2se/1.4/docs/api/java/lang/Object.html?is-external=true#wait(long,%20int)\"" }, //Member summary table link. {BUG_ID + FS + "pkg" + FS + "C1.html", - "href=\"../pkg/C1.html#method(int, int, java.util.ArrayList)\"" + "href=\"../pkg/C1.html#method(int,%20int,%20java.util.ArrayList)\"" }, //Anchor test. {BUG_ID + FS + "pkg" + FS + "C1.html", @@ -66,11 +66,11 @@ }, //{@link} test. {BUG_ID + FS + "pkg" + FS + "C2.html", - "Link: " + "Link: " }, //@see test. {BUG_ID + FS + "pkg" + FS + "C2.html", - "See Also:" + NL + "
" + "See Also:" + NL + "
" }, //Header does not link to the page itself. diff -r a3d8494cdba0 -r 1f40f52b3ccc langtools/test/com/sun/javadoc/testJavascript/TestJavascript.java --- a/langtools/test/com/sun/javadoc/testJavascript/TestJavascript.java Tue Sep 24 14:35:24 2013 -0700 +++ b/langtools/test/com/sun/javadoc/testJavascript/TestJavascript.java Wed Sep 25 07:36:37 2013 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 4665566 4855876 7025314 8012375 8015997 + * @bug 4665566 4855876 7025314 8012375 8015997 8016328 * @summary Verify that the output has the right javascript. * @author jamieh * @library ../lib/ @@ -56,6 +56,12 @@ " if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + NL + " targetPage = \"undefined\";" + NL + " function validURL(url) {" + NL + + " try {" + NL + + " url = decodeURIComponent(url);" + NL + + " }" + NL + + " catch (error) {" + NL + + " return false;" + NL + + " }" + NL + " var pos = url.indexOf(\".html\");" + NL + " if (pos == -1 || pos != url.length - 5)" + NL + " return false;" + NL + @@ -67,7 +73,8 @@ " if ('a' <= ch && ch <= 'z' ||" + NL + " 'A' <= ch && ch <= 'Z' ||" + NL + " ch == '$' ||" + NL + - " ch == '_') {" + NL + + " ch == '_' ||" + NL + + " ch.charCodeAt(0) > 127) {" + NL + " allowNumber = true;" + NL + " allowSep = true;" + NL + " } else if ('0' <= ch && ch <= '9'" + NL + diff -r a3d8494cdba0 -r 1f40f52b3ccc langtools/test/com/sun/javadoc/testLinkTaglet/TestLinkTaglet.java --- a/langtools/test/com/sun/javadoc/testLinkTaglet/TestLinkTaglet.java Tue Sep 24 14:35:24 2013 -0700 +++ b/langtools/test/com/sun/javadoc/testLinkTaglet/TestLinkTaglet.java Wed Sep 25 07:36:37 2013 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 4732864 6280605 7064544 8014636 + * @bug 4732864 6280605 7064544 8014636 8016328 * @summary Make sure that you can link from one member to another using * non-qualified name, furthermore, ensure the right one is linked. * @author jamieh @@ -49,9 +49,9 @@ "Qualified Link: C.InnerC.
" + NL + " Unqualified Link1: C.InnerC.
" + NL + " Unqualified Link2: C.InnerC.
" + NL + - " Qualified Link: method(pkg.C.InnerC, pkg.C.InnerC2).
" + NL + - " Unqualified Link: method(C.InnerC, C.InnerC2).
" + NL + - " Unqualified Link: method(InnerC, InnerC2).
" + " Qualified Link: method(pkg.C.InnerC, pkg.C.InnerC2).
" + NL + + " Unqualified Link: method(C.InnerC, C.InnerC2).
" + NL + + " Unqualified Link: method(InnerC, InnerC2).
" }, {BUG_ID + FS + "pkg" + FS + "C.InnerC.html", "Link to member in outer class: C.MEMBER
" + NL + diff -r a3d8494cdba0 -r 1f40f52b3ccc langtools/test/com/sun/javadoc/testPrivateClasses/TestPrivateClasses.java --- a/langtools/test/com/sun/javadoc/testPrivateClasses/TestPrivateClasses.java Tue Sep 24 14:35:24 2013 -0700 +++ b/langtools/test/com/sun/javadoc/testPrivateClasses/TestPrivateClasses.java Wed Sep 25 07:36:37 2013 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 4780441 4874845 4978816 8014017 + * @bug 4780441 4874845 4978816 8014017 8016328 * @summary Make sure that when the -private flag is not used, members * inherited from package private class are documented in the child. * @@ -177,7 +177,7 @@ // Should document that a method overrides method from private class. {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html", "
Overrides:
" + NL + - "
" + + "
" + "methodOverridenFromParent in class " + "" + "PrivateParent
"}, diff -r a3d8494cdba0 -r 1f40f52b3ccc langtools/test/com/sun/javadoc/testUseOption/TestUseOption.java --- a/langtools/test/com/sun/javadoc/testUseOption/TestUseOption.java Tue Sep 24 14:35:24 2013 -0700 +++ b/langtools/test/com/sun/javadoc/testUseOption/TestUseOption.java Wed Sep 25 07:36:37 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2013, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 4496290 4985072 7006178 7068595 + * @bug 4496290 4985072 7006178 7068595 8016328 * @summary A simple test to determine if -use works. * @author jamieh * @library ../lib/ @@ -60,7 +60,7 @@ "UsedInC in <Unnamed>" }, {BUG_ID + "-3" + FS + "package-use.html", "" + - "UsedInC " + "UsedInC " } };