8048628: javadoc strips HTML incorrectly; causes invalid generated HTML files
authorksrini
Fri, 27 Jan 2017 10:08:36 -0800
changeset 43568 0126b1f1e2be
parent 43567 d0d89c3da7be
child 43569 717da20a1807
8048628: javadoc strips HTML incorrectly; causes invalid generated HTML files Reviewed-by: jjg
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
langtools/test/com/sun/javadoc/testNonInlineHtmlTagRemoval/C.java
langtools/test/com/sun/javadoc/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java
langtools/test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/C.java
langtools/test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Wed Feb 01 11:25:56 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Fri Jan 27 10:08:36 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, 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
@@ -1723,9 +1723,29 @@
                     break main;
                 ch = text.charAt(currPos);
             }
-            if (ch == '>' && blockTags.contains(StringUtils.toLowerCase(text.substring(tagPos, currPos)))) {
+            String tagFound = StringUtils.toLowerCase(text.substring(tagPos, currPos));
+            if (blockTags.contains(tagFound)) {
                 result.append(text, startPos, lessThanPos);
+                currPos = tagPos + tagFound.length();
+                boolean foundGT = false;
+                Character quoteKind = null;
+                while (!foundGT) {
+                    if (ch == '\"' || ch == '\'') {
+                        if (quoteKind == null) {
+                            quoteKind = ch;
+                        } else if (quoteKind == ch) {
+                            quoteKind = null;
+                        }
+                    }
+                    if (ch == '>' && quoteKind == null) {
+                        foundGT = true;
+                    }
+                    if (++currPos == len)
+                        break;
+                    ch = text.charAt(currPos);
+                }
                 startPos = currPos + 1;
+                currPos = startPos;
             }
             lessThanPos = text.indexOf('<', currPos);
         }
@@ -1740,6 +1760,10 @@
                 ('1' <= ch && ch <= '6');
     }
 
+    private static boolean isWhitespace(char ch) {
+        return Character.isWhitespace(ch);
+    }
+
     /**
      * Add a link to the stylesheet file.
      *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testNonInlineHtmlTagRemoval/C.java	Fri Jan 27 10:08:36 2017 -0800
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2017, 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.
+ */
+
+public class C {
+    /**
+     * case1 <ul> <li> end of sentence. <li> more </ul>
+     */
+    public void case1() {}
+
+    /**
+     * case2 <ul compact> <li> end of sentence. <li> more </ul>
+     */
+    public void case2() {}
+
+    /**
+     * case3 <ul type="square"> <li> end of sentence. <li> more </ul>
+     */
+    public void case3() {}
+
+    /**
+     * case4 <ul type="a<b"> <li> end of sentence. <li> more </ul>
+     */
+    public void case4() {}
+
+    /**
+     * case5 <ul type="a>b"> <li> end of sentence. <li> more </ul>
+     */
+    public void case5() {}
+
+    /**
+     * case6 <ul type='a>b'> <li> end of sentence. <li> more </ul>
+     */
+    public void case6() {}
+
+    /**
+     * case7 <ul type='"a>b"'> <li> end of sentence. <li> more </ul>
+     */
+    public void case7() {}
+
+    /**
+     * case8 <ul type="'a>b'"> <li> end of sentence. <li> more </ul>
+     */
+    public void case8() {}
+
+    /**
+     * case9 <ul type="'a'>b"> <li> end of sentence. <li> more </ul>
+     */
+    public void case9() {}
+
+    /**
+     * caseA <ul type='"a">b'> <li> end of sentence. <li> more </ul>
+     */
+    public void caseA() {}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java	Fri Jan 27 10:08:36 2017 -0800
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2017, 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      8048628
+ * @summary  Verify html inline tags are removed correctly in the first sentence.
+ * @library  ../lib
+ * @modules jdk.javadoc
+ * @build    JavadocTester
+ * @run main TestNonInlineHtmlTagRemoval
+ */
+
+public class TestNonInlineHtmlTagRemoval extends JavadocTester {
+
+    public static void main(String... args) throws Exception {
+        TestNonInlineHtmlTagRemoval tester = new TestNonInlineHtmlTagRemoval();
+        tester.runTests();
+    }
+
+    @Test
+    void test() {
+        javadoc("-d", "out",
+                "-sourcepath", testSrc,
+                testSrc("C.java"));
+        checkExit(Exit.OK);
+
+        checkOutput("C.html", true,
+                "<div class=\"block\">case1 end of sentence.</div>",
+                "<div class=\"block\">case2 end of sentence.</div>",
+                "<div class=\"block\">case3 end of sentence.</div>",
+                "<div class=\"block\">case4 end of sentence.</div>",
+                "<div class=\"block\">case5 end of sentence.</div>",
+                "<div class=\"block\">case6 end of sentence.</div>",
+                "<div class=\"block\">case7 end of sentence.</div>",
+                "<div class=\"block\">case8 end of sentence.</div>",
+                "<div class=\"block\">case9 end of sentence.</div>",
+                "<div class=\"block\">caseA end of sentence.</div>");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/C.java	Fri Jan 27 10:08:36 2017 -0800
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2017, 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.
+ */
+
+public class C {
+    /**
+     * case1 <ul> <li> end of sentence. <li> more </ul>
+     */
+    public void case1() {}
+
+    /**
+     * case2 <ul compact> <li> end of sentence. <li> more </ul>
+     */
+    public void case2() {}
+
+    /**
+     * case3 <ul type="square"> <li> end of sentence. <li> more </ul>
+     */
+    public void case3() {}
+
+    /**
+     * case4 <ul type="a<b"> <li> end of sentence. <li> more </ul>
+     */
+    public void case4() {}
+
+    /**
+     * case5 <ul type="a>b"> <li> end of sentence. <li> more </ul>
+     */
+    public void case5() {}
+
+    /**
+     * case6 <ul type='a>b'> <li> end of sentence. <li> more </ul>
+     */
+    public void case6() {}
+
+    /**
+     * case7 <ul type='"a>b"'> <li> end of sentence. <li> more </ul>
+     */
+    public void case7() {}
+
+    /**
+     * case8 <ul type="'a>b'"> <li> end of sentence. <li> more </ul>
+     */
+    public void case8() {}
+
+    /**
+     * case9 <ul type="'a'>b"> <li> end of sentence. <li> more </ul>
+     */
+    public void case9() {}
+
+    /**
+     * caseA <ul type='"a">b'> <li> end of sentence. <li> more </ul>
+     */
+    public void caseA() {}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/jdk/javadoc/doclet/testNonInlineHtmlTagRemoval/TestNonInlineHtmlTagRemoval.java	Fri Jan 27 10:08:36 2017 -0800
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2017, 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      8048628
+ * @summary  Verify html inline tags are removed correctly in the first sentence.
+ * @library  ../lib
+ * @modules jdk.javadoc/jdk.javadoc.internal.tool
+ * @build    JavadocTester
+ * @run main TestNonInlineHtmlTagRemoval
+ */
+
+public class TestNonInlineHtmlTagRemoval extends JavadocTester {
+
+    public static void main(String... args) throws Exception {
+        TestNonInlineHtmlTagRemoval tester = new TestNonInlineHtmlTagRemoval();
+        tester.runTests();
+    }
+
+    @Test
+    void test() {
+        javadoc("-d", "out",
+                "-sourcepath", testSrc,
+                testSrc("C.java"));
+        checkExit(Exit.OK);
+
+        checkOutput("C.html", true,
+                "<div class=\"block\">case1   end of sentence.</div>",
+                "<div class=\"block\">case2   end of sentence.</div>",
+                "<div class=\"block\">case3   end of sentence.</div>",
+                "<div class=\"block\">case4   end of sentence.</div>",
+                "<div class=\"block\">case5   end of sentence.</div>",
+                "<div class=\"block\">case6   end of sentence.</div>",
+                "<div class=\"block\">case7   end of sentence.</div>",
+                "<div class=\"block\">case8   end of sentence.</div>",
+                "<div class=\"block\">case9   end of sentence.</div>",
+                "<div class=\"block\">caseA   end of sentence.</div>");
+    }
+}