8195805: Doclet incorrectly updates all attributes in <a> tags when relocating links
authorjjg
Mon, 22 Jan 2018 11:28:32 -0800
changeset 48655 e1876e6b57b6
parent 48654 36f58bd6269f
child 48656 fd237da7a113
8195805: Doclet incorrectly updates all attributes in <a> tags when relocating links Reviewed-by: ksrini
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java
test/langtools/jdk/javadoc/doclet/testRelativeLinks/TestRelativeLinks.java
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Mon Jan 22 11:15:51 2018 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Mon Jan 22 11:28:32 2018 -0800
@@ -1752,8 +1752,9 @@
                     result.addContent(sb);
                     Content docRootContent = new ContentBuilder();
 
+                    boolean isHRef = inAnAtag() && node.getName().toString().equalsIgnoreCase("href");
                     for (DocTree dt : node.getValue()) {
-                        if (utils.isText(dt) && inAnAtag()) {
+                        if (utils.isText(dt) && isHRef) {
                             String text = ((TextTree) dt).getBody();
                             if (text.startsWith("/..") && !configuration.docrootparent.isEmpty()) {
                                 result.addContent(configuration.docrootparent);
--- a/test/langtools/jdk/javadoc/doclet/testRelativeLinks/TestRelativeLinks.java	Mon Jan 22 11:15:51 2018 -0800
+++ b/test/langtools/jdk/javadoc/doclet/testRelativeLinks/TestRelativeLinks.java	Mon Jan 22 11:28:32 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, 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      4460354 8014636 8043186
+ * @bug      4460354 8014636 8043186 8195805
  * @summary  Test to make sure that relative paths are redirected in the
  *           output so that they are not broken.
  * @author   jamieh
@@ -67,7 +67,12 @@
             "<a href=\"./pkg/relative-field-link.html\">relative field link</a>",
             "<a href=\"./pkg/relative-method-link.html\">relative method link</a>",
             "<a href=\"./pkg/relative-package-link.html\">relative package link</a>",
-            " <a href=\"./pkg/relative-multi-line-link.html\">relative-multi-line-link</a>.",
+            " <a href=\"./pkg/relative-multi-line-link.html\">relative-multi-line-link</a>.");
+
+        // This is not a relative path and should not be redirected.
+        checkOutput("index-all.html", true,
+            "<div class=\"block\"><a name=\"masters\"></a>");
+        checkOutput("index-all.html", false,
             "<div class=\"block\"><a name=\"./pkg/masters\"></a>");
 
         // PACKAGE USE