zoffixznet / JavaScript-Minifier

JavaScript::Minifier perl module
9 stars 6 forks source link

Sometimes fails with / as it thinks regexp is a division or vice versa #2

Closed zoffixznet closed 3 years ago

zoffixznet commented 10 years ago

Failing JS: https://rt.cpan.org/Ticket/Attachment/803747/416658/jquery.tablesorter.js

Wed Jun 25 11:44:34 2008 kev@brantaero.com - Ticket #37091: Ticket created [Reply] [Forward]

Subject: "unterminated regular expression literal" when using CDATA without slash afterwards Download (untitled) / with headers text/plain 771b On perl5.10/win32: This was a bit tough to track down, but if I load and try to minimize a file containing these lines: ""+<![CDATA[ ]]>; ...then I get the following error: unterminated regular expression literal, stopped at JavaScript/Minifier.pm line 151. However, if I add any line to the file involving a slash, it works: ""+<![CDATA[ ]]>; 2/2; ...gets me no error. Also, stripDebug makes no difference, it still breaks without the slash, and is fine when it's there. This isn't actually critical for me, because I had been using this CDATA setup to embed CSS in my JS files, which I'll now be separating out again so that I can minify the CSS as well. But since I encountered it, and this is valid JavaScript, I thought I should report it.

Wed Jul 14 05:22:16 2010 mg.pub@gmx.net - Ticket created [Reply] [Forward]

Subject: unterminated regular expression literal on a very simple valid regular expression Download (untitled) / with headers text/plain 899b While trying to minify the jQuery TableSorter plugin (http://tablesorter.com/docs/), JavaScript::Minifier 1.05 crashed with the error message given in the subject of this report. The smallest piece of sourcecode causing the crash is: function test(s) { return /\d{1,2}/.test(s); } A workaround would be function test(s) { return (/\d{1,2}/).test(s); } But since our software should allow for customization and also external JavaScript code which is beyond our control, it would be GREAT if you could consider fixing this bug report. Maybe you want to minify the entire tablesorter plugin file which I attached after the bug is fixed. This has more complicated regular expressions inside, like this one: ... is: function(s) { return /\d{1,2}[\/-]\d{1,2}[\/-]\d{2,4}/.test(s); }, ... Thanks for considering, I would be very happy about a solution in the near future. Best regards, mg Subject: jquery.tablesorter.js Download jquery.tablesorter.js application/x-javascript 22.8k

Message body not shown because it is not plain text.

Mon Jan 20 19:10:28 2014 cpan@zoffix.com - Correspondence added [Reply] [Forward]

Download (untitled) / with headers text/plain 514b Going to stall this for now. The issue is this: the way the original author wrote the code makes the module think the opening '/' on the regex is actually a division, because the previous word "return" ends on an alphanumeric character ( basically, it thinks the regex is the beginning of " n / SOMETHING". I need to read up more on how JS parsers figure this one out, and then think up a fix :) Thanks for reporting (yeah, I know it's been years hehe :)) -- Cheers, ZZ [ https://metacpan.org/author/ZOFFIX ]

Mon Jan 20 19:10:28 2014 The RT System itself - Status changed from 'new' to 'open'

Mon Jan 20 19:10:29 2014 cpan@zoffix.com - Status changed from 'open' to 'stalled'

Mon Jan 20 19:10:29 2014 cpan@zoffix.com - Taken

Mon Jan 20 19:53:43 2014 cpan@zoffix.com - Ticket #37091: Merged into ticket #59355

Mon Jan 20 19:53:43 2014 cpan@zoffix.com - Merged into ticket #59355

zoffixznet commented 3 years ago

Appears to have been fixed by https://github.com/zoffixznet/JavaScript-Minifier/pull/11