@@ -215,6 +215,56 @@ describe('Marp', () => {
215215 expect ( $ ( 'header > strong' ) ) . toHaveLength ( 1 )
216216 expect ( $ ( 'footer > em' ) ) . toHaveLength ( 1 )
217217 } )
218+
219+ it ( 'keeps raw HTML comments within valid HTML block' , ( ) => {
220+ const { html : $script , comments : comments$script } = marp ( ) . render (
221+ "<script><!--\nconst script = '<b>test</b>'\n--></script>"
222+ )
223+ expect ( $script ) . toContain ( "const script = '<b>test</b>'" )
224+ expect ( comments$script [ 0 ] ) . toHaveLength ( 0 )
225+
226+ // Complex comment
227+ const complexComment = `
228+ <!--
229+ function matchwo(a,b)
230+ {
231+
232+ if (a < b && a < 0) then {
233+ return 1;
234+
235+ } else {
236+
237+ return 0;
238+ }
239+ }
240+
241+ // ex
242+ -->
243+ ` . trim ( )
244+ const { html : $complex } = marp ( ) . render (
245+ `<script>${ complexComment } </script>`
246+ )
247+ expect ( $complex ) . toContain ( complexComment )
248+
249+ // NOTE: Marpit framework will collect the comment block if the whole of HTML block was comment
250+ const { html : $comment , comments : comments$comment } = marp ( ) . render (
251+ "<!--\nconst script = '<b>test</b>'\n-->"
252+ )
253+ expect ( $comment ) . not . toContain ( "const script = '<b>test</b>'" )
254+ expect ( comments$comment [ 0 ] ) . toHaveLength ( 1 )
255+ } )
256+
257+ it ( 'sanitizes CDATA section' , ( ) => {
258+ // HTML Living Standard denys using CDATA in HTML context so must be sanitized
259+ const cdata = `
260+ <![CDATA[
261+ <p>XSS</p>
262+ <script>alert('XSS')</script>
263+ ]]>
264+ ` . trim ( )
265+ const { html } = marp ( ) . render ( cdata )
266+ expect ( html ) . not . toContain ( cdata )
267+ } )
218268 } )
219269
220270 describe ( 'with true' , ( ) => {
0 commit comments