Skip to content

Commit de011c1

Browse files
committed
Add tests for CDATA parsing
1 parent 2f2db2e commit de011c1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/minifier.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,30 @@ QUnit.test('collapsing space in conditional comments', function(assert) {
623623
}), output);
624624
});
625625

626+
QUnit.test('(bug) CDATA parsed as conditional comments', function(assert) {
627+
var input;
628+
629+
input = '<![CDATA[line 1\nline 2]]>';
630+
assert.equal(minify(input), input);
631+
assert.equal(minify(input, { removeComments: true }), '');
632+
input = '<p><![CDATA[line 1\nline 2]]></p>';
633+
assert.equal(minify(input), input);
634+
assert.equal(minify(input, { removeComments: true }), '<p></p>');
635+
636+
input = '<![CDATA[]]>';
637+
assert.equal(minify(input), input);
638+
assert.equal(minify(input, { removeComments: true }), '');
639+
640+
// https://github.com/kangax/html-minifier/issues/1161
641+
input = '<![CDATA[___]><-___]]>';
642+
assert.throws(function() {
643+
minify(input);
644+
}, '"]>" treated as end instead of "]]>" (bug)');
645+
assert.throws(function() {
646+
minify(input, { removeComments: true });
647+
}, '"]>" treated as end instead of "]]>" (bug)');
648+
});
649+
626650
QUnit.test('remove comments from scripts', function(assert) {
627651
var input, output;
628652

0 commit comments

Comments
 (0)