2

I'm attempting to utilize wro4j (1.6.2 and 1.6.3-SNAPSHOT) under maven and I've run into a problem with the jquery.tablesorter.js plugin.

On line 972 (or there about) there is a regex that eclipse and the wro4j JSMin (java port) are not liking.

return /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);

So here's the problem. In Eclipse Indigo, the part '/.test(s);' is showing up as a string (blue highlight). JSMin chokes on it throwing an UnterminatedRegexException.

I've run the C based JSMin against the same file with no problem. What am I missing here?

Doing the following seems to mitigate it but I'm not understanding why this is considered an unterminated regex literal.

return /(\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4})/.test(s);
Dave G
  • 9,639
  • 36
  • 41
  • 2
    It's valid JavaScript, if your tool does not like it, your tool is bad ;) – Felix Kling Jan 24 '13 at 18:36
  • wrap it in parenthesis and see if that makes a difference or use `new RegEx()` and see if that helps. – epascarello Jan 24 '13 at 18:39
  • I contacted the author about this. All other date expressions in tablesorter use ^ and $ except this one (shortDate). As to the veracity of the tools - I have no clue. – Dave G Jan 24 '13 at 19:43
  • Notepad++ JSMin plug-in chokes on this also, but not if you remove the `{2,4}` or add any other character to the end of the regex. – MikeM Jan 24 '13 at 19:53
  • JsMin in its latest/current state will NOT fail on `return (/endswith(punctuation)/).test(a)` but will fail on `return /endswith(punctuation)/.test(a)` because it does not understand keywords. It doesn't know that "return" cannot precede a division symbol, so it believes the `/endswith(punctuation)` part is NOT a RegExp but the `/.test(a)` part IS a RegExp. Don't expect a fix for this ever, it would be better to switch away from JsMin. Even the README says "Warning: Do not use this awful, awful code or any other thing like it. / Seriously." – AndrewF Sep 04 '19 at 00:17

1 Answers1

2

The JsMin java port has some known limitations. Unless you have a good reason to continue using JsMin, I would suggest to try googleClosure to handle the js minimization.

Also, when finding this kind of problem, feel free to open an issue and probably it will be fixed in next release.

Alex Objelean
  • 3,893
  • 2
  • 27
  • 36
  • Hey Alex - Thanks for chiming in! I happened to have stumbled across it and if it is a limitation - great no worries. Thanks for the input! – Dave G Jan 25 '13 at 01:22
  • I see you also filed this http://code.google.com/p/wro4j/issues/detail?id=660 this afternoon. Thank you! – Dave G Jan 25 '13 at 01:24