Skip to content

Commit b007d9b

Browse files
committed
Fix for KT-13038 Quick doc should escape HTML entities in code blocks
1 parent 2cd6c85 commit b007d9b

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,12 @@ object KDocRenderer {
203203
MarkdownTokenTypes.RPAREN,
204204
MarkdownTokenTypes.LBRACKET,
205205
MarkdownTokenTypes.RBRACKET,
206-
MarkdownTokenTypes.EXCLAMATION_MARK,
207-
MarkdownTokenTypes.CODE_FENCE_CONTENT-> {
206+
MarkdownTokenTypes.EXCLAMATION_MARK -> {
208207
sb.append(nodeText)
209208
}
209+
MarkdownTokenTypes.CODE_FENCE_CONTENT -> {
210+
sb.append(nodeText.htmlEscape())
211+
}
210212
MarkdownTokenTypes.EOL -> {
211213
val parentType = node.parent?.type
212214
if (parentType == MarkdownElementTypes.CODE_BLOCK || parentType == MarkdownElementTypes.CODE_FENCE) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Code block:
3+
* ``` kotlin
4+
* A<T>
5+
* ```
6+
* Code span:
7+
* `<T>` is type parameter
8+
*/
9+
class <caret>A<T>
10+
11+
//INFO: <b>public</b> <b>final</b> <b>class</b> A&lt;T&gt; <i>defined in</i> root package<p>Code block:</p>
12+
//INFO: <pre><code>
13+
//INFO: A&lt;T&gt;
14+
//INFO: </code></pre><p>Code span: <code>&lt;T&gt;</code> is type parameter</p>

idea/tests/org/jetbrains/kotlin/idea/editor/quickDoc/QuickDocProviderTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ public void testConstructorVarParameter() throws Exception {
7272
doTest(fileName);
7373
}
7474

75+
@TestMetadata("EscapeHtmlInsideCodeBlocks.kt")
76+
public void testEscapeHtmlInsideCodeBlocks() throws Exception {
77+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/quickDoc/EscapeHtmlInsideCodeBlocks.kt");
78+
doTest(fileName);
79+
}
80+
7581
@TestMetadata("JavaClassUsedInKotlin.kt")
7682
public void testJavaClassUsedInKotlin() throws Exception {
7783
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/quickDoc/JavaClassUsedInKotlin.kt");

0 commit comments

Comments
 (0)