Subject: | regex can cause 'unterminated quoted string literal' error |
Hi,
This module is awesome.
I'd like to let you know about an issue I'm having when minifying the
Tablesorter plugin for jQuery.
Download: http://tablesorter.com/jquery.tablesorter.zip
File: tablesorter/jquery.tablesorter.js
Line: 796
return /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);
This line causes the minify function to croak with the message
"unterminated quoted string literal".
I was able to reproduce the failure with these cases:
perl -MJavaScript::Minifier::XS=minify -e 'minify(q{return
/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);})'
perl -MJavaScript::Minifier::XS=minify -e 'minify(q{return
/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/;})'
perl -MJavaScript::Minifier::XS=minify -e 'minify(q{return /\d+/;})'
After reading the XS code and trying some more test cases, I think I can
narrow down the problem a little. It appears to involve this condition
in JsTokenizeString():
/* see if we're "division" or "regexp" */
if (ch && ((ch == ')') || (ch == '.') || (ch == ']') ||
(charIsIdentifier(ch))))
_JsExtractSigil(&doc, node); /* division */
else
_JsExtractLiteral(&doc, node); /* regexp */
It looks like the first '/' delimiter for the regex is being
interpreted as division because the 'return' keyword matches an
identifier character and satisfies the condition.
Replacing 'return' in front of the regex with a character that doesn't
match the first condition prevents the error message, and replacing
'return' with any other character that would match the first condition
causes the error message to appear.
I'm interested to know if you are able to reproduce this problem or if
it could be something wrong with my configuration.
Let me know if you need any more information.