Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minifier blocks process - 100% cpu usage #443

Closed
ownagedj opened this issue Dec 2, 2015 · 2 comments
Closed

minifier blocks process - 100% cpu usage #443

ownagedj opened this issue Dec 2, 2015 · 2 comments

Comments

@ownagedj
Copy link

ownagedj commented Dec 2, 2015

When I try to minify my file

test.html

<script src="4e650aacd2bf30e34e650aacd2bf30e34e650aacd2bf30e34e650aacd2bf30e3"

commands

node;
var minify = require('html-minifier').minify;
var template = fs.readFileSync('./test.html').toString();
minify(template);

The minify process takes like forever. It uses 100% from one of my cpu cores.
The way to stop the process is to kill it with killall node -9

If I use less chars in the src part then it speeds up and results in an Parse Error which is correct behavior.

Also tried the other versions (0.8.0, 0.7.0, ...)with the same result

I think there is something broken.

@GriffinSauce
Copy link

I had the same issue with the following snippet of (invalid) HTML:

<input class="class-name1 class-name2" / data-attributewithoutvalue>

Sure this is invalid HTML (due to the /) but locking the cpu at 100% is not the behaviour I'd expect.
I can't describe the exact cause but can note some exclusions:

  • removing the / fixes it
  • removing the classnames fixes it (produces an error)
  • removing the data attribute at the end fixes it

@duncanbeevers
Copy link
Collaborator

This is a duplicate of #332

The root cause is the html parser being powered by regular expressions which behave well when faced with valid input, but fall victim to catastrophic backtracking when faced with invalid input.

http://www.regular-expressions.info/catastrophic.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants