Skip to content

Commit a8871f5

Browse files
8305407: ExternalSpecsWriter should ignore white-space differences in spec titles
Reviewed-by: hannesw
1 parent 6b2a86a commit a8871f5

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ExternalSpecsWriter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected void checkUniqueItems() {
132132
for (IndexItem ii : configuration.mainIndex.getItems(DocTree.Kind.SPEC)) {
133133
if (ii.getDocTree() instanceof SpecTree st) {
134134
String url = st.getURL().toString();
135-
String title = st.getTitle().toString();
135+
String title = ii.getLabel(); // normalized form of st.getTitle()
136136
itemsByTitle
137137
.computeIfAbsent(title, l -> new HashMap<>())
138138
.computeIfAbsent(url, u -> new ArrayList<>())

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ protected Content indexTagOutput(Element element, IndexTree tag) {
222222
DocTree searchTerm = tag.getSearchTerm();
223223
String tagText = (searchTerm instanceof TextTree tt) ? tt.getBody() : "";
224224
if (tagText.charAt(0) == '"' && tagText.charAt(tagText.length() - 1) == '"') {
225-
tagText = tagText.substring(1, tagText.length() - 1)
226-
.replaceAll("\\s+", " ");
225+
tagText = tagText.substring(1, tagText.length() - 1);
227226
}
227+
tagText = tagText.replaceAll("\\s+", " ");
228228

229229
Content desc = htmlWriter.commentTagsToContent(element, tag.getDescription(), context.within(tag));
230230
String descText = extractText(desc);
@@ -771,7 +771,8 @@ private Content specTagToContent(Element holder, SpecTree specTree) {
771771
String specTreeURL = specTree.getURL().getBody();
772772
List<? extends DocTree> specTreeLabel = specTree.getTitle();
773773
Content label = htmlWriter.commentTagsToContent(holder, specTreeLabel, isFirstSentence);
774-
return getExternalSpecContent(holder, specTree, specTreeURL, textOf(specTreeLabel), label);
774+
return getExternalSpecContent(holder, specTree, specTreeURL,
775+
textOf(specTreeLabel).replaceAll("\\s+", " "), label);
775776
}
776777

777778
Content getExternalSpecContent(Element holder, DocTree docTree, String url, String searchText, Content title) {

test/langtools/jdk/javadoc/doclet/testSpecTag/TestSpecTag.java

+46-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 6251738 8226279 8297802 8296546
26+
* @bug 6251738 8226279 8297802 8296546 8305407
2727
* @summary JDK-8226279 javadoc should support a new at-spec tag
2828
* @library /tools/lib ../../lib
2929
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -415,6 +415,51 @@ public void m2() { }
415415
.replace("#FILE#", src.resolve("p").resolve("C.java").toString()));
416416
}
417417

418+
@Test
419+
public void testDifferentWhitespaceTitlesForURL(Path base) throws IOException {
420+
Path src = base.resolve("src");
421+
tb.writeJavaFiles(src, """
422+
package p;
423+
/** Class C. */
424+
public class C {
425+
private C() { }
426+
427+
/**
428+
* Method m1.
429+
* @spec http://example.com/index.html abc def
430+
*/
431+
public void m1() { }
432+
433+
/**
434+
* Method m2.
435+
* @spec http://example.com/index.html abc def
436+
*/
437+
public void m2() { }
438+
}
439+
""");
440+
441+
javadoc("-d", base.resolve("out").toString(),
442+
"--source-path", src.toString(),
443+
"p");
444+
checkExit(Exit.OK);
445+
446+
checkOutput(Output.OUT, false, "error");
447+
448+
checkOutput("external-specs.html", true,
449+
"""
450+
<div class="summary-table two-column-summary">
451+
<div class="table-header col-first">Specification</div>
452+
<div class="table-header col-last">Referenced In</div>
453+
<div class="col-first even-row-color"><a href="http://example.com/index.html">abc def</a></div>
454+
<div class="col-last even-row-color">
455+
<ul class="ref-list">
456+
<li><code><a href="p/C.html#abcdef">p.C.m1()</a></code></li>
457+
<li><code><a href="p/C.html#abcdef-1">p.C.m2()</a></code></li>
458+
</ul>
459+
</div>
460+
</div>""");
461+
}
462+
418463
@Test
419464
public void testMultipleURLsForTitle(Path base) throws IOException {
420465
Path src = base.resolve("src");

0 commit comments

Comments
 (0)