douglascrockford/JSMin — Issue #4: JSMin gives error when parsing a specific string
Author: kap0w
Created: 2011-12-20 12:57:56+00:00
State: open

Hi,

We are currently experiencing problems with using JSMin. The javascript code that causes us problems is this:

var pattern=/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;

The usage is this:
$jsmin_php = JSMin::minify(file_get_contents("error.js"));
echo $jsmin_php;

The error thrown is this:
Fatal error: Uncaught exception 'JSMin_UnterminatedStringException' with message 'Unterminated String: '\'*+/=?^_`{|}~-]+)*|"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$/;'' in /home/kasper/kaspergrubbe.dk/htdocs/JSMin.php:151 Stack trace: #0 /home/kasper/kaspergrubbe.dk/htdocs/JSMin.php(123): JSMin->action(1) #1 /home/kasper/kaspergrubbe.dk/htdocs/JSMin.php(80): JSMin->min() #2 /home/kasper/kaspergrubbe.dk/htdocs/JSMin.php(53): JSMin::minify('var pattern=/^(...') #3 {main} thrown in /home/kasper/kaspergrubbe.dk/htdocs/JSMin.php on line 151