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

Minifying html with empty body and removeOptionalTags crashes #500

Closed
Conduitry opened this issue Feb 20, 2016 · 1 comment
Closed

Minifying html with empty body and removeOptionalTags crashes #500

Conduitry opened this issue Feb 20, 2016 · 1 comment

Comments

@Conduitry
Copy link

Attempting to minify a document with an empty body, and with the removeOptionalTags flag set to true, crashes:

> require('html-minifier').minify('<body></body>', { removeOptionalTags: true })
RangeError: Invalid array length
    at removeEndTag ([...]/htmlminifier.js:792:21)
    at Object.minify ([...]/htmlminifier.js:1051:9)
[...]

The problem seems to be that removeEndTag() is called while buffer is an empty array. index gets set to -1, the loop gets bypassed, but then we try to set buffer.length to -1.

I noticed this issue appear in 1.2.0; it did not happen in 1.1.1.

@alexlamsl
Copy link
Collaborator

Thanks for reporting this - I have submitted a fix in #501

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

2 participants