Skip to content

Loading…

Regex Detection Failure #13

Open
furkanmustafa opened this Issue · 8 comments

6 participants

@furkanmustafa

(rev:b3d0a82) Cannot detect this regex and fails with 'Stray Regex Pattern' error.

        return /\?/ .test( url ) ? "&" : "?";
  • This regex cannot get detected on line 233 because it doesn't have wrapping quotes.
  • And it gets detected on line 248, but it catches the ending of regex, because it has question mark before getting closed. saveRegex() gets called (after the end of regex)
  • So, saveRegex() function goes until the end of line and fails.
@klatys

I encountered different problem with regex when trying to pack benchmark.js

When parsing these lines method saveString detects it as a unclosed string and throws an exception

// detect strings containing only the "use strict" directive
    return /^(?:\/\*+[\w|\W]*?\*\/|\/\/.*?[\n\r\u2028\u2029]|\s)*(["'])use strict\1;?$/.test(result)
      ? ''
      : result;
@stefetom

Hello,

Similar problem for me with this javascript :

function testURL(link)
{
  return /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(link);
}

Result :

Fatal error: Uncaught exception 'RuntimeException' with message 'Unclosed string at position: 1193' in ...
@furkanmustafa

and none of the developers cared apparently. I've almost forgot about this issue.

@kAlvaro

Feel free to send a pull request; that's the whole point of GitHub.

P.S. I'm not affiliated or involved with this project.

@tedivm
Tedious Developments member

If this fix was as simple as you guys are claiming (half an hour?) you can all feel free to do it. I've made a couple of attempts at resolving it myself (you can see some of the dead branches) and in many cases the fixes proposed broke more things than they resolved. This isn't exactly a dead project- JShrink has had multiple releases and a lot of work done on it, so acting like I just don't care is a real dick move.

Right now there are 0 open pull requests for this project. If one of you would like to get off your asses and submit a request that solves this I'll happily review it and pull it back in if it works. Just remember that I expect it to be solved with out breaking anything else, so it has to pass the test suite. Feel free to read the Contributors document for more advice on adding to this project.

@furkanmustafa

You could just put a comment and let us know it was being difficult, or at least you've seen the issue. It looked like you didn't care. Sorry for making a "real dick move". I'll give it a try to fix it when I have a chance.

@eisberg

Hi,
problem in regexp in HighCharts Library (4.0.4, highstock.js):

Test code:

$jsCode = '{dSetter:function(a,b,c){a&&a.join&&(a=a.join(" "));/(NaN| {2}|^$)/.test(a)&&(a="M 0 0");}';
$s =\JShrink\Minifier::minify($jsCode );
    var_dump($jsCode);
    var_dump($s); //JS Error -  Uncaught SyntaxError: Invalid regular expression: /(NaN|{2}|^$)/: Nothing to repeat

Output:

string(90) "{dSetter:function(a,b,c){a&&a.join&&(a=a.join(" "));/(NaN| {2}|^$)/.test(a)&&(a="M 0 0");}"
string(89) "{dSetter:function(a,b,c){a&&a.join&&(a=a.join(" "));/(NaN|{2}|^$)/.test(a)&&(a="M 0 0");}"

@tedivm
Tedious Developments member

@furkanmustafa you still planning on giving a fix a try?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.