8016328: Regression : Javadoc i18n regression caused by fix for 8012375

Reviewed-by: jjg
This commit is contained in:
Bhavesh Patel 2013-09-24 16:12:06 -07:00
parent 48d1808d53
commit 2233312946
7 changed files with 73 additions and 18 deletions

View file

@ -28,6 +28,7 @@ package com.sun.tools.doclets.formats.html.markup;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.util.*; import java.util.*;
import java.nio.charset.*;
import com.sun.tools.doclets.internal.toolkit.Content; import com.sun.tools.doclets.internal.toolkit.Content;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
@ -163,6 +164,46 @@ public class HtmlTree extends Content {
return s; return s;
} }
/**
* 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. * Generates an HTML anchor tag.
* *
@ -172,7 +213,7 @@ public class HtmlTree extends Content {
*/ */
public static HtmlTree A(String ref, Content body) { public static HtmlTree A(String ref, Content body) {
HtmlTree htmltree = new HtmlTree(HtmlTag.A, nullCheck(body)); HtmlTree htmltree = new HtmlTree(HtmlTag.A, nullCheck(body));
htmltree.addAttr(HtmlAttr.HREF, ref); htmltree.addAttr(HtmlAttr.HREF, encodeURL(ref));
return htmltree; return htmltree;
} }

View file

@ -335,6 +335,12 @@ public class HtmlWriter {
" if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + DocletConstants.NL + " if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + DocletConstants.NL +
" targetPage = \"undefined\";" + DocletConstants.NL + " targetPage = \"undefined\";" + DocletConstants.NL +
" function validURL(url) {" + 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 + " var pos = url.indexOf(\".html\");" + DocletConstants.NL +
" if (pos == -1 || pos != url.length - 5)" + DocletConstants.NL + " if (pos == -1 || pos != url.length - 5)" + DocletConstants.NL +
" return false;" + DocletConstants.NL + " return false;" + DocletConstants.NL +
@ -346,7 +352,8 @@ public class HtmlWriter {
" if ('a' <= ch && ch <= 'z' ||" + DocletConstants.NL + " if ('a' <= ch && ch <= 'z' ||" + DocletConstants.NL +
" 'A' <= ch && ch <= 'Z' ||" + DocletConstants.NL + " 'A' <= ch && ch <= 'Z' ||" + DocletConstants.NL +
" ch == '$' ||" + DocletConstants.NL + " ch == '$' ||" + DocletConstants.NL +
" ch == '_') {" + DocletConstants.NL + " ch == '_' ||" + DocletConstants.NL +
" ch.charCodeAt(0) > 127) {" + DocletConstants.NL +
" allowNumber = true;" + DocletConstants.NL + " allowNumber = true;" + DocletConstants.NL +
" allowSep = true;" + DocletConstants.NL + " allowSep = true;" + DocletConstants.NL +
" } else if ('0' <= ch && ch <= '9'" + DocletConstants.NL + " } else if ('0' <= ch && ch <= '9'" + DocletConstants.NL +

View file

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 4663254 * @bug 4663254 8016328
* @summary Verify that spaces do not appear in hrefs and anchors. * @summary Verify that spaces do not appear in hrefs and anchors.
* @author jamieh * @author jamieh
* @library ../lib/ * @library ../lib/
@ -46,11 +46,11 @@ public class TestHref extends JavadocTester {
private static final String[][] TEST = { private static final String[][] TEST = {
//External link. //External link.
{BUG_ID + FS + "pkg" + FS + "C1.html", {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. //Member summary table link.
{BUG_ID + FS + "pkg" + FS + "C1.html", {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. //Anchor test.
{BUG_ID + FS + "pkg" + FS + "C1.html", {BUG_ID + FS + "pkg" + FS + "C1.html",
@ -66,11 +66,11 @@ public class TestHref extends JavadocTester {
}, },
//{@link} test. //{@link} test.
{BUG_ID + FS + "pkg" + FS + "C2.html", {BUG_ID + FS + "pkg" + FS + "C2.html",
"Link: <a href=\"../pkg/C1.html#method(int, int, java.util.ArrayList)\">" "Link: <a href=\"../pkg/C1.html#method(int,%20int,%20java.util.ArrayList)\">"
}, },
//@see test. //@see test.
{BUG_ID + FS + "pkg" + FS + "C2.html", {BUG_ID + FS + "pkg" + FS + "C2.html",
"See Also:</span></dt>" + NL + "<dd><a href=\"../pkg/C1.html#method(int, int, java.util.ArrayList)\">" "See Also:</span></dt>" + NL + "<dd><a href=\"../pkg/C1.html#method(int,%20int,%20java.util.ArrayList)\">"
}, },
//Header does not link to the page itself. //Header does not link to the page itself.

View file

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 4665566 4855876 7025314 8012375 8015997 * @bug 4665566 4855876 7025314 8012375 8015997 8016328
* @summary Verify that the output has the right javascript. * @summary Verify that the output has the right javascript.
* @author jamieh * @author jamieh
* @library ../lib/ * @library ../lib/
@ -56,6 +56,12 @@ public class TestJavascript extends JavadocTester {
" if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + NL + " if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + NL +
" targetPage = \"undefined\";" + NL + " targetPage = \"undefined\";" + NL +
" function validURL(url) {" + 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 + " var pos = url.indexOf(\".html\");" + NL +
" if (pos == -1 || pos != url.length - 5)" + NL + " if (pos == -1 || pos != url.length - 5)" + NL +
" return false;" + NL + " return false;" + NL +
@ -67,7 +73,8 @@ public class TestJavascript extends JavadocTester {
" if ('a' <= ch && ch <= 'z' ||" + NL + " if ('a' <= ch && ch <= 'z' ||" + NL +
" 'A' <= ch && ch <= 'Z' ||" + NL + " 'A' <= ch && ch <= 'Z' ||" + NL +
" ch == '$' ||" + NL + " ch == '$' ||" + NL +
" ch == '_') {" + NL + " ch == '_' ||" + NL +
" ch.charCodeAt(0) > 127) {" + NL +
" allowNumber = true;" + NL + " allowNumber = true;" + NL +
" allowSep = true;" + NL + " allowSep = true;" + NL +
" } else if ('0' <= ch && ch <= '9'" + NL + " } else if ('0' <= ch && ch <= '9'" + NL +

View file

@ -23,7 +23,7 @@
/* /*
* @test * @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 * @summary Make sure that you can link from one member to another using
* non-qualified name, furthermore, ensure the right one is linked. * non-qualified name, furthermore, ensure the right one is linked.
* @author jamieh * @author jamieh
@ -49,9 +49,9 @@ public class TestLinkTaglet extends JavadocTester {
"Qualified Link: <a href=\"../pkg/C.InnerC.html\" title=\"class in pkg\"><code>C.InnerC</code></a>.<br/>" + NL + "Qualified Link: <a href=\"../pkg/C.InnerC.html\" title=\"class in pkg\"><code>C.InnerC</code></a>.<br/>" + NL +
" Unqualified Link1: <a href=\"../pkg/C.InnerC.html\" title=\"class in pkg\"><code>C.InnerC</code></a>.<br/>" + NL + " Unqualified Link1: <a href=\"../pkg/C.InnerC.html\" title=\"class in pkg\"><code>C.InnerC</code></a>.<br/>" + NL +
" Unqualified Link2: <a href=\"../pkg/C.InnerC.html\" title=\"class in pkg\"><code>C.InnerC</code></a>.<br/>" + NL + " Unqualified Link2: <a href=\"../pkg/C.InnerC.html\" title=\"class in pkg\"><code>C.InnerC</code></a>.<br/>" + NL +
" Qualified Link: <a href=\"../pkg/C.html#method(pkg.C.InnerC, pkg.C.InnerC2)\"><code>method(pkg.C.InnerC, pkg.C.InnerC2)</code></a>.<br/>" + NL + " Qualified Link: <a href=\"../pkg/C.html#method(pkg.C.InnerC,%20pkg.C.InnerC2)\"><code>method(pkg.C.InnerC, pkg.C.InnerC2)</code></a>.<br/>" + NL +
" Unqualified Link: <a href=\"../pkg/C.html#method(pkg.C.InnerC, pkg.C.InnerC2)\"><code>method(C.InnerC, C.InnerC2)</code></a>.<br/>" + NL + " Unqualified Link: <a href=\"../pkg/C.html#method(pkg.C.InnerC,%20pkg.C.InnerC2)\"><code>method(C.InnerC, C.InnerC2)</code></a>.<br/>" + NL +
" Unqualified Link: <a href=\"../pkg/C.html#method(pkg.C.InnerC, pkg.C.InnerC2)\"><code>method(InnerC, InnerC2)</code></a>.<br/>" " Unqualified Link: <a href=\"../pkg/C.html#method(pkg.C.InnerC,%20pkg.C.InnerC2)\"><code>method(InnerC, InnerC2)</code></a>.<br/>"
}, },
{BUG_ID + FS + "pkg" + FS + "C.InnerC.html", {BUG_ID + FS + "pkg" + FS + "C.InnerC.html",
"Link to member in outer class: <a href=\"../pkg/C.html#MEMBER\"><code>C.MEMBER</code></a> <br/>" + NL + "Link to member in outer class: <a href=\"../pkg/C.html#MEMBER\"><code>C.MEMBER</code></a> <br/>" + NL +

View file

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 4780441 4874845 4978816 8014017 * @bug 4780441 4874845 4978816 8014017 8016328
* @summary Make sure that when the -private flag is not used, members * @summary Make sure that when the -private flag is not used, members
* inherited from package private class are documented in the child. * inherited from package private class are documented in the child.
* *
@ -177,7 +177,7 @@ public class TestPrivateClasses extends JavadocTester {
// Should document that a method overrides method from private class. // Should document that a method overrides method from private class.
{BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html", {BUG_ID + "-2" + FS + "pkg" + FS + "PublicChild.html",
"<dt><span class=\"strong\">Overrides:</span></dt>" + NL + "<dt><span class=\"strong\">Overrides:</span></dt>" + NL +
"<dd><code><a href=\"../pkg/PrivateParent.html#methodOverridenFromParent(char[], int, T, V, java.util.List)\">" + "<dd><code><a href=\"../pkg/PrivateParent.html#methodOverridenFromParent(char[],%20int,%20T,%20V,%20java.util.List)\">" +
"methodOverridenFromParent</a></code>&nbsp;in class&nbsp;<code>" + "methodOverridenFromParent</a></code>&nbsp;in class&nbsp;<code>" +
"<a href=\"../pkg/PrivateParent.html\" title=\"class in pkg\">" + "<a href=\"../pkg/PrivateParent.html\" title=\"class in pkg\">" +
"PrivateParent</a></code></dd>"}, "PrivateParent</a></code></dd>"},

View file

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 4496290 4985072 7006178 7068595 * @bug 4496290 4985072 7006178 7068595 8016328
* @summary A simple test to determine if -use works. * @summary A simple test to determine if -use works.
* @author jamieh * @author jamieh
* @library ../lib/ * @library ../lib/
@ -60,7 +60,7 @@ public class TestUseOption extends JavadocTester {
"UsedInC</a> in <a href=\"../package-summary.html\">&lt;Unnamed&gt;</a>" "UsedInC</a> in <a href=\"../package-summary.html\">&lt;Unnamed&gt;</a>"
}, },
{BUG_ID + "-3" + FS + "package-use.html", "<td class=\"colOne\">" + {BUG_ID + "-3" + FS + "package-use.html", "<td class=\"colOne\">" +
"<a href=\"class-use/UsedInC.html#&lt;Unnamed&gt;\">UsedInC</a>&nbsp;</td>" "<a href=\"class-use/UsedInC.html#%3CUnnamed%3E\">UsedInC</a>&nbsp;</td>"
} }
}; };