diff --git a/src/htmlparser.js b/src/htmlparser.js index b6ecffc3..3e39debd 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -140,6 +140,17 @@ function HTMLParser(html, handler) { } } + // Treat as a comment for backward compatibility. It was + // was unintentionally parsed as a conditional comment before + // https://github.com/kangax/html-minifier/pull/1162. + if (html.startsWith(''); + handler.comment(html.substring(2, cdataEnd + 2), true /* non-standard */); + html = html.substring(cdataEnd + 3); + prevTag = ''; + continue; + } + // https://en.wikipedia.org/wiki/Conditional_comment#Downlevel-revealed_conditional_comment if (/^'); diff --git a/tests/minifier.js b/tests/minifier.js index ff848d8e..0865de1c 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -623,6 +623,26 @@ QUnit.test('collapsing space in conditional comments', function(assert) { }), output); }); +QUnit.test('treat CDATA as comments for backward compatibility', function(assert) { + var input; + + input = ''; + assert.equal(minify(input), input); + assert.equal(minify(input, { removeComments: true }), ''); + input = '

'; + assert.equal(minify(input), input); + assert.equal(minify(input, { removeComments: true }), '

'); + + input = ''; + assert.equal(minify(input), input); + assert.equal(minify(input, { removeComments: true }), ''); + + // https://github.com/kangax/html-minifier/issues/1161 + input = '<-___]]>'; + assert.equal(minify(input), input); + assert.equal(minify(input, { removeComments: true }), ''); +}); + QUnit.test('remove comments from scripts', function(assert) { var input, output;