Skip to content

Commit

Permalink
fix: improve comment cleanup regex
Browse files Browse the repository at this point in the history
  • Loading branch information
catalan-adobe committed Feb 13, 2024
1 parent 6b05e99 commit 0a16dc5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/DOMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default class DOMUtils {
document.body.innerHTML = document.body.innerHTML
// remove html comments
.replace(/(>\s*)<!--(?!>)[\S\s]*?-->/gm, '$1')
.replace(/\n<!--(?!>)[\S\s]*?-->/gm, '\n');
.replace(/<!--(?!>)[\S\s]*?-->/gm, '');
}

static removeSpans(document) {
Expand Down
1 change: 1 addition & 0 deletions test/utils/DOMUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ describe('DOMUtils#removeCommments tests', () => {
test('<p><!-- useless comment \n multiline --></p>', '<p></p>');
test('<p><!-- useless comment \n multiline \n multiline --></p>', '<p></p>');
test('<!-- useless comment --><p>The content stays</p><!-- another useless comment with \n line break -->', '<p>The content stays</p>');
test('<p>The content stays<!-- useless comment inside an element --></p>', '<p>The content stays</p>');
test('<p>The content and spaces stay</p> <!-- a useless comment preceded by spaces -->', '<p>The content and spaces stay</p> ');
test('<p>This is a paragraph.</p>\n\x3C!--\n<p>Look at this cool image:</p>\n<img border="0" src="pic_trulli.jpg" alt="Trulli">\n-->\n<p>This is a paragraph too.</p>\x3C!-- same line -->\n\x3C!-- single line -->', '<p>This is a paragraph.</p>\n\n<p>This is a paragraph too.</p>\n');
test('<div some-crazy-attribute="" <!--=""><!-- useless comment --></div>', '<div some-crazy-attribute="" <!--=""></div>');
Expand Down

0 comments on commit 0a16dc5

Please sign in to comment.