changeset 1428:17ee569d0c01 jdk7u25-b09

8012375: Improve Javadoc framing Reviewed-by: mduigou, jlaskey
author bpatel
date Fri, 26 Apr 2013 15:24:12 -0700
parents 4dbd21d15a39
children 41c1b02cd6a8
files src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java test/com/sun/javadoc/testJavascript/TestJavascript.java
diffstat 2 files changed, 72 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java	Tue Apr 23 16:23:22 2013 -0700
+++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java	Fri Apr 26 15:24:12 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -312,8 +312,41 @@
         String scriptCode = DocletConstants.NL + "    targetPage = \"\" + window.location.search;" + DocletConstants.NL +
                 "    if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
                 "        targetPage = targetPage.substring(1);" + DocletConstants.NL +
-                "    if (targetPage.indexOf(\":\") != -1)" + DocletConstants.NL +
+                "    if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + DocletConstants.NL +
                 "        targetPage = \"undefined\";" + DocletConstants.NL +
+                "    function validURL(url) {" + DocletConstants.NL +
+                "        if (!(url.indexOf(\".html\") == url.length - 5))" + DocletConstants.NL +
+                "            return false;" + DocletConstants.NL +
+                "        var allowNumber = false;" + DocletConstants.NL +
+                "        var allowSep = false;" + DocletConstants.NL +
+                "        var seenDot = false;" + DocletConstants.NL +
+                "        for (var i = 0; i < url.length - 5; i++) {" + DocletConstants.NL +
+                "            var ch = url.charAt(i);" + DocletConstants.NL +
+                "            if ('a' <= ch && ch <= 'z' ||" + DocletConstants.NL +
+                "                    'A' <= ch && ch <= 'Z' ||" + DocletConstants.NL +
+                "                    ch == '$' ||" + DocletConstants.NL +
+                "                    ch == '_') {" + DocletConstants.NL +
+                "                allowNumber = true;" + DocletConstants.NL +
+                "                allowSep = true;" + DocletConstants.NL +
+                "            } else if ('0' <= ch && ch <= '9'" + DocletConstants.NL +
+                "                    || ch == '-') {" + DocletConstants.NL +
+                "                if (!allowNumber)" + DocletConstants.NL +
+                "                     return false;" + DocletConstants.NL +
+                "            } else if (ch == '/' || ch == '.') {" + DocletConstants.NL +
+                "                if (!allowSep)" + DocletConstants.NL +
+                "                    return false;" + DocletConstants.NL +
+                "                allowNumber = false;" + DocletConstants.NL +
+                "                allowSep = false;" + DocletConstants.NL +
+                "                if (ch == '.')" + DocletConstants.NL +
+                "                     seenDot = true;" + DocletConstants.NL +
+                "                if (ch == '/' && seenDot)" + DocletConstants.NL +
+                "                     return false;" + DocletConstants.NL +
+                "            } else {" + DocletConstants.NL +
+                "                return false;"+ DocletConstants.NL +
+                "            }" + DocletConstants.NL +
+                "        }" + DocletConstants.NL +
+                "        return true;" + DocletConstants.NL +
+                "    }" + DocletConstants.NL +
                 "    function loadFrames() {" + DocletConstants.NL +
                 "        if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
                 "             top.classFrame.location = top.targetPage;" + DocletConstants.NL +
--- a/test/com/sun/javadoc/testJavascript/TestJavascript.java	Tue Apr 23 16:23:22 2013 -0700
+++ b/test/com/sun/javadoc/testJavascript/TestJavascript.java	Fri Apr 26 15:24:12 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 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      4665566 4855876 7025314
+ * @bug      4665566 4855876 7025314 8012375
  * @summary  Verify that the output has the right javascript.
  * @author   jamieh
  * @library  ../lib/
@@ -35,7 +35,7 @@
 public class TestJavascript extends JavadocTester {
 
     //Test information.
-    private static final String BUG_ID = "4665566-4855876";
+    private static final String BUG_ID = "4665566-4855876-8012375";
 
     //Javadoc arguments.
     private static final String[] ARGS = new String[] {
@@ -53,8 +53,41 @@
                         "    targetPage = \"\" + window.location.search;" + NL +
             "    if (targetPage != \"\" && targetPage != \"undefined\")" + NL +
             "        targetPage = targetPage.substring(1);" + NL +
-            "    if (targetPage.indexOf(\":\") != -1)" + NL +
+            "    if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + NL +
             "        targetPage = \"undefined\";" + NL +
+            "    function validURL(url) {" + NL +
+            "        if (!(url.indexOf(\".html\") == url.length - 5))" + NL +
+            "            return false;" + NL +
+            "        var allowNumber = false;" + NL +
+            "        var allowSep = false;" + NL +
+            "        var seenDot = false;" + NL +
+            "        for (var i = 0; i < url.length - 5; i++) {" + NL +
+            "            var ch = url.charAt(i);" + NL +
+            "            if ('a' <= ch && ch <= 'z' ||" + NL +
+            "                    'A' <= ch && ch <= 'Z' ||" + NL +
+            "                    ch == '$' ||" + NL +
+            "                    ch == '_') {" + NL +
+            "                allowNumber = true;" + NL +
+            "                allowSep = true;" + NL +
+            "            } else if ('0' <= ch && ch <= '9'" + NL +
+            "                    || ch == '-') {" + NL +
+            "                if (!allowNumber)" + NL +
+            "                     return false;" + NL +
+            "            } else if (ch == '/' || ch == '.') {" + NL +
+            "                if (!allowSep)" + NL +
+            "                    return false;" + NL +
+            "                allowNumber = false;" + NL +
+            "                allowSep = false;" + NL +
+            "                if (ch == '.')" + NL +
+            "                     seenDot = true;" + NL +
+            "                if (ch == '/' && seenDot)" + NL +
+            "                     return false;" + NL +
+            "            } else {" + NL +
+            "                return false;" + NL +
+            "            }" + NL +
+            "        }" + NL +
+            "        return true;" + NL +
+            "    }" + NL +
             "    function loadFrames() {" + NL +
             "        if (targetPage != \"\" && targetPage != \"undefined\")" + NL +
             "             top.classFrame.location = top.targetPage;" + NL +