Skip to content

[Bug]: Minifying CSS deletes blocks of code #180

@chrisstaite-menlo

Description

@chrisstaite-menlo

What happened?

When running the minifier with the following input:

<style type="text/css">
{% ignore1 %}
a {
    {% ignore2 %}
}
{% ignore3 %}
</style>

And settings:

{
   ignoreCustomFragments: [
      /\{%[\s\S]*?%\}/
   ],
   collapseWhitespace: true,
   conservativeCollapse: true,
   minifyCSS: {
      level: 0
   },
}

The output is:

<style type="text/css"> {% ignore1 %} a{ {% ignore2 %} }</style>

Where it should be:

<style type="text/css"> {% ignore1 %} a{ {% ignore2 %} } {% ignore3 %} </style>

Full test program:

const { minify } = require('html-minifier-terser');

const html = `<style type="text/css">
{% ignore1 %}
a {
    {% ignore2 %}
}
{% ignore3 %}
</style>`;

const output = minify(html, {
  ignoreCustomFragments: [/\{%[\s\S]*?%\}/],
  collapseWhitespace: true,
  conservativeCollapse: true,
  minifyCSS: {
    level: 0,
  },
}).then(console.info);

Version

7.2.0

What browsers are you seeing the problem on?

No response

Link to reproduce

https://stackblitz.com/edit/node-hnsagk?file=index.js

Relevant log output

No response

Willing to submit a PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions