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

fix: <?php ?>0 in script will throw an error #1001

Closed

Conversation

zhihuahuang
Copy link

@zhihuahuang zhihuahuang commented Mar 21, 2019

If you use minifyJS options, a number after custom fragments in script will throw an error.

Like this:

let html = `<script>var value = "<?php ?>+<?php ?>0";</script>`;

minify(html, {
    minifyJS: true,
});

It will be throw a TypeError.

TypeError: Cannot read property '0' of undefined
    at html-minifier/src/htmlminifier.js:1266:52

I found that the cause is the regular expression uidAttr + ([0-9]+). It will match the extra numbers. So I added parentheses to the regular expression.

@alexlamsl
Copy link
Collaborator

Please add some test cases to demonstrate this fix. Also may I suggest uidAttr + ([0-9]+?) + uidAttr instead of adding parenthesis for better resilience.

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

Successfully merging this pull request may close these issues.

3 participants