terinjokes / gulp-uglify

Minify files with UglifyJS
MIT License
1.23k stars 154 forks source link

Infinite Loop #333

Closed kaljak closed 6 years ago

kaljak commented 6 years ago

I got this Javascript:

function abc() {
  var s = "Test";
  s = ['<tpl>', s, '</tpl>'].join('');

  var re = /<tpl>.*<\/tpl>/;
  var m, id = 0;

  while(m = s.match(re)){
    s = s.replace(m[0], '{xtpl'+ id + '}');
    ++id;
  }
};

This javascript is reduced to:

function abc(){for(var t,l="Test",p=/<tpl>.*<\/tpl>/,a=0;t=(l=["<tpl>",l,"</tpl>"].join("")).match(p);)l=l.replace(t[0],"{xtpl"+a+"}"),++a}

This results in an endlos loop because variable "l" because it is used in the for condition

alexlamsl commented 6 years ago

Thanks for the report - next time please file them in https://github.com/mishoo/UglifyJS2/issues instead.

Fix is pending at https://github.com/mishoo/UglifyJS2/pull/3139