8204330: Javadoc IllegalArgumentException: HTML special chars in constant value
Reviewed-by: ksrini
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java Mon Jun 18 13:40:16 2018 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java Mon Jun 18 13:52:30 2018 -0700
@@ -176,8 +176,6 @@
HtmlTree fixedNavDiv = new HtmlTree(HtmlTag.DIV);
- final static Pattern IMPROPER_HTML_CHARS = Pattern.compile(".*[&<>].*");
-
/**
* The window title of this file.
*/
@@ -910,15 +908,7 @@
*/
public Content getDocLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element element,
CharSequence label, boolean strong, boolean isProperty) {
- return getDocLink(context, typeElement, element, new StringContent(check(label)), strong, isProperty);
- }
-
- CharSequence check(CharSequence s) {
- Matcher m = IMPROPER_HTML_CHARS.matcher(s);
- if (m.matches()) {
- throw new IllegalArgumentException(s.toString());
- }
- return s;
+ return getDocLink(context, typeElement, element, new StringContent(label), strong, isProperty);
}
public Content getDocLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element element,
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java Mon Jun 18 13:40:16 2018 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java Mon Jun 18 13:52:30 2018 -0700
@@ -406,9 +406,9 @@
* {@inheritDoc}
*/
public Content valueTagOutput(VariableElement field, String constantVal, boolean includeLink) {
- return includeLink ?
- htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field,
- constantVal, false) : new RawHtml(constantVal);
+ return includeLink
+ ? htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field, constantVal, false)
+ : new StringContent(constantVal);
}
/**
--- a/test/langtools/jdk/javadoc/doclet/testValueTag/TestValueTag.java Mon Jun 18 13:40:16 2018 -0700
+++ b/test/langtools/jdk/javadoc/doclet/testValueTag/TestValueTag.java Mon Jun 18 13:52:30 2018 -0700
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 4764045 8004825 8026567 8191030
+ * @bug 4764045 8004825 8026567 8191030 8204330
* @summary This test ensures that the value tag works in all
* use cases, the tests are explained below.
* @author jamieh
@@ -33,6 +33,12 @@
* @run main TestValueTag
*/
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
public class TestValueTag extends JavadocTester {
public static void main(String... args) throws Exception {
@@ -110,7 +116,7 @@
checkForException();
}
- @Test()
+ @Test
void test2() {
javadoc("-Xdoclint:none",
"-d", "out2",
@@ -133,7 +139,7 @@
checkForException();
}
- @Test()
+ @Test
void test3() {
javadoc("-d", "out3",
"-sourcepath", testSrc,
@@ -146,10 +152,37 @@
"The value2 is <a href=\"#CONSTANT\">\"constant\"</a>.",
"The value3 is <a href=\"../pkg2/Class3.html#TEST_12_PASSES\">"
+ "\"Test 12 passes\"</a>.");
+ checkForException();
+ }
+
+ @Test
+ void test4() throws IOException {
+ Path base = Paths.get("test4");
+ Path src = base.resolve("src");
+ Files.createDirectories(src.resolve("p"));
+ Files.write(src.resolve("p").resolve("C.java"), List.of(
+ "package p;",
+ "/** This class defines specialChars: {@value C#specialChars}. */",
+ "public class C {",
+ " /** The value is {@value}. */",
+ " public static final String specialChars = \"abc < def & ghi > jkl\";",
+ "}"));
+
+ javadoc("-d", base.resolve("out").toString(),
+ "-sourcepath", src.toString(),
+ "p");
+ checkExit(Exit.OK);
+ checkOutput("p/C.html", false,
+ "The value is \"abc < def & ghi > jkl\".");
+ checkOutput("p/C.html", true,
+ "The value is \"abc < def & ghi > jkl\".");
+
+ checkForException();
}
void checkForException() {
checkOutput(Output.STDERR, false, "DocletAbortException");
+ checkOutput(Output.STDERR, false, "IllegalArgumentException");
}
}