@@ -15,7 +15,7 @@ class MarkdownTestCase extends Assert
1515 @ Test
1616 public void testMdHeadingToHtml ()
1717 {
18- MarkdownService markdownService = MarkdownService . get ();
18+ MarkdownService markdownService = new MarkdownServiceImpl ();
1919 String testMdText = "# This is a H1 header" ;
2020 String expectedHtmlText = "<div class=\" lk-markdown-container\" ><h1 id=\" this-is-a-h1-header\" >This is a H1 header</h1>\n </div>" ;
2121 String htmlText = markdownService .toHtml (testMdText );
@@ -28,7 +28,7 @@ public void testMdHeadingToHtml()
2828 @ Test
2929 public void testMdBoldToHtml ()
3030 {
31- MarkdownService markdownService = MarkdownService . get ();
31+ MarkdownService markdownService = new MarkdownServiceImpl ();
3232 String testMdText = "**This is bold text**" ;
3333 String expectedHtmlText = "<div class=\" lk-markdown-container\" ><p><strong>This is bold text</strong></p>\n </div>" ;
3434 String htmlText = markdownService .toHtml (testMdText );
@@ -41,11 +41,10 @@ public void testMdBoldToHtml()
4141 @ Test
4242 public void testMdHtmlTags ()
4343 {
44- MarkdownService markdownService = MarkdownService .get ();
45-
44+ MarkdownService markdownService = new MarkdownServiceImpl ();
4645 String testMdText = "<h2>header</h2>" ;
47- String expectedHtmlText = "<div class=\" lk-markdown-container\" ><p><h2>header</h2></p>\n </div>" ;
4846 String htmlText = markdownService .toHtml (testMdText );
47+ String expectedHtmlText = "<div class=\" lk-markdown-container\" ><p><h2>header</h2></p>\n </div>" ;
4948 assertEquals ("The MarkdownService failed to correctly escape html tags." , expectedHtmlText , htmlText );
5049
5150 testMdText = "<script>alert()</script>" ;
@@ -60,7 +59,7 @@ public void testMdHtmlTags()
6059 @ Test
6160 public void testMdComplexToHtml ()
6261 {
63- MarkdownService markdownService = MarkdownService . get ();
62+ MarkdownService markdownService = new MarkdownServiceImpl ();
6463 // this sample of markdown and translation taken from part of: https://markdown-it.github.io/
6564 String testMdText = """
6665 ---
@@ -341,4 +340,20 @@ public void testMdComplexToHtml()
341340 String htmlText = markdownService .toHtml (testMdText );
342341 assertEquals ("The MarkdownService failed to correctly translate complex markdown text to html." , expectedHtmlText , htmlText );
343342 }
343+ @ Test
344+ public void testHtmlComments ()
345+ {
346+ MarkdownService markdownService = new MarkdownServiceImpl ();
347+
348+ String testMdText = "Text before <!-- comment --> text after" ;
349+ String htmlText = markdownService .toHtml (testMdText );
350+
351+ assertTrue ("Comment was encoded: " + htmlText , htmlText .contains ("<!-- comment -->" ));
352+ assertFalse ("Comment should not be encoded: " + htmlText , htmlText .contains ("<!--" ));
353+
354+ // Verification for <script> still being encoded
355+ String scriptMd = "<script>alert('hi')</script>" ;
356+ String scriptHtml = markdownService .toHtml (scriptMd );
357+ assertTrue ("Script tags should still be encoded: " + scriptHtml , scriptHtml .contains ("<script>" ));
358+ }
344359}
0 commit comments