Skip to content

Commit 80cd41a

Browse files
Incorrect handling of inlines tags in Markdown
This PR fixes a generic issue in Markdown where an extra TextElement is created when an inline tag ends at the end of the Markdown content, resulting in incorrect parsing behavior. Fix: #4743
1 parent d5cfab4 commit 80cd41a

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ protected boolean commentParse() {
551551
refreshInlineTagPosition(textEndPosition);
552552
setInlineTagStarted(false);
553553
} else if (this.lineStarted && this.textStart != -1 && this.textStart <= textEndPosition && (this.textStart < this.starPosition || this.starPosition == lastStarPosition || this.markdown)) {
554-
pushText(this.textStart, textEndPosition);
554+
if (!(invalidInlineTagLineEnd > 0 && nextCharacter == '}' && this.markdown && this.index == this.javadocEnd))
555+
pushText(this.textStart, textEndPosition);
555556
}
556557
updateDocComment();
557558
} catch (Exception ex) {

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterMarkdownTest.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,4 +2234,84 @@ public class Markdown{}
22342234
assertEquals("incorrect Fifth tagElement", ASTNode.TAG_ELEMENT, tags.get(4).getNodeType());
22352235
}
22362236
}
2237+
2238+
public void testIncorrectLinkTagParsing4743_01() throws JavaModelException {
2239+
String source ="""
2240+
/// {@link java.lang.String}
2241+
public class Markdown{}
2242+
""";
2243+
this.workingCopies = new ICompilationUnit[1];
2244+
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/Markdown.java", source, null);
2245+
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
2246+
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
2247+
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
2248+
Javadoc javadoc = typedeclaration.getJavadoc();
2249+
List<TagElement> tags = javadoc.tags();
2250+
TagElement firstTag = tags.get(0);
2251+
List<?> frags = firstTag.fragments();
2252+
assertEquals("Incorrect Frags", 1, frags.size());
2253+
TagElement innerTag = (TagElement) frags.get(0);
2254+
assertEquals("invalid tag name","@link" ,innerTag.getTagName());
2255+
}
2256+
}
2257+
2258+
public void testIncorrectLinkTagParsing4743_02() throws JavaModelException {
2259+
String source ="""
2260+
/// {@linkplain java.lang.String}
2261+
public class Markdown{}
2262+
""";
2263+
this.workingCopies = new ICompilationUnit[1];
2264+
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/Markdown.java", source, null);
2265+
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
2266+
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
2267+
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
2268+
Javadoc javadoc = typedeclaration.getJavadoc();
2269+
List<TagElement> tags = javadoc.tags();
2270+
TagElement firstTag = tags.get(0);
2271+
List<?> frags = firstTag.fragments();
2272+
assertEquals("Incorrect Frags", 1, frags.size());
2273+
TagElement innerTag = (TagElement) frags.get(0);
2274+
assertEquals("invalid tag name","@linkplain" ,innerTag.getTagName());
2275+
}
2276+
}
2277+
2278+
public void testIncorrectLinkTagParsing4743_03() throws JavaModelException {
2279+
String source ="""
2280+
/// {@code List<String>}
2281+
public class Markdown{}
2282+
""";
2283+
this.workingCopies = new ICompilationUnit[1];
2284+
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/Markdown.java", source, null);
2285+
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
2286+
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
2287+
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
2288+
Javadoc javadoc = typedeclaration.getJavadoc();
2289+
List<TagElement> tags = javadoc.tags();
2290+
TagElement firstTag = tags.get(0);
2291+
List<?> frags = firstTag.fragments();
2292+
assertEquals("Incorrect Frags", 1, frags.size());
2293+
TagElement innerTag = (TagElement) frags.get(0);
2294+
assertEquals("invalid tag name","@code" ,innerTag.getTagName());
2295+
}
2296+
}
2297+
2298+
public void testIncorrectLinkTagParsing4743_04() throws JavaModelException {
2299+
String source ="""
2300+
/// {@literal List<String>}
2301+
public class Markdown{}
2302+
""";
2303+
this.workingCopies = new ICompilationUnit[1];
2304+
this.workingCopies[0] = getWorkingCopy("/Converter_25/src/markdown/Markdown.java", source, null);
2305+
if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
2306+
CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
2307+
TypeDeclaration typedeclaration = (TypeDeclaration) compilUnit.types().get(0);
2308+
Javadoc javadoc = typedeclaration.getJavadoc();
2309+
List<TagElement> tags = javadoc.tags();
2310+
TagElement firstTag = tags.get(0);
2311+
List<?> frags = firstTag.fragments();
2312+
assertEquals("Incorrect Frags", 1, frags.size());
2313+
TagElement innerTag = (TagElement) frags.get(0);
2314+
assertEquals("invalid tag name","@literal" ,innerTag.getTagName());
2315+
}
2316+
}
22372317
}

0 commit comments

Comments
 (0)