Skip to content

Commit

Permalink
fix: fix downlevel-revealed closing comment being deleted in safe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
santialbo committed Apr 15, 2024
1 parent 5a53068 commit b14f416
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export function isComment(content) {
}

export function isConditionalComment(content) {
return (content || '').trim().startsWith('<!--[if');
const clean = (content || '').trim();
return clean.startsWith('<!--[if') || clean === '<!--<![endif]-->';
}

export function isStyleNode(node) {
Expand Down
2 changes: 1 addition & 1 deletion test/modules/minifyConditionalComments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('minifyConditionalComments', () => {
<div class="w3c">
</div>
<!--<![endif]-->`,
multipleConditionalCommentMinified: '<!--[if lt IE 7 ]><div class="ie6"> </div><![endif]--><!--[if IE 7 ]><div class="ie7"> </div><![endif]--><!--[if IE 8 ]><div class="ie8"> </div><![endif]--><!--[if IE 9 ]><div class="ie9"> </div><![endif]--><!--[if (gt IE 9)|!(IE)]><!--><div class="w3c"> </div>',
multipleConditionalCommentMinified: '<!--[if lt IE 7 ]><div class="ie6"> </div><![endif]--><!--[if IE 7 ]><div class="ie7"> </div><![endif]--><!--[if IE 8 ]><div class="ie8"> </div><![endif]--><!--[if IE 9 ]><div class="ie9"> </div><![endif]--><!--[if (gt IE 9)|!(IE)]><!--><div class="w3c"> </div><!--<![endif]-->',
singleLineMultipleConditionalComment: `
<!--[if lt IE 7 ]><div class="ie6"></div><![endif]--><!--[if IE 7 ]><div class="ie7"></div><![endif]--><!--[if IE 8 ]><div class="ie8"></div><![endif]--><!--[if IE 9 ]><div class="ie9"></div><![endif]--><!--[if (gt IE 9)|!(IE)]><!--><div class="w3c"></div><!--<![endif]-->`,
htmlTagIncludedConditionalComment: `
Expand Down
8 changes: 8 additions & 0 deletions test/modules/removeComments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe('removeComments', () => {
);
});

it('should not remove conditional comments <!--[if expression]><!-->..<!--<![endif]-->', () => {
return init(
'<!--[if !mso]><!--><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]-->',
'<!--[if !mso]><!--><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]-->',
options
);
});

it('should not remove conditional comments <!--[if expression]>..<![endif]-->', () => {
return init(
'<!--[if IE 8]><link href="ie8only.css" rel="stylesheet"><![endif]-->',
Expand Down

0 comments on commit b14f416

Please sign in to comment.