rburns / ansi-to-html

Convert ansi escaped text streams to html.
MIT License
354 stars 48 forks source link

Infinite loop with specific ANSI string #101

Open Sembiance opened 2 years ago

Sembiance commented 2 years ago

The following code will produce an infinite loop that ansi-to-html never returns from:

var Convert = require('ansi-to-html');
var convert = new Convert();
console.log(convert.toHtml('\u001b[15;1!\u001b[17;2!\u001b[11;0;3549;3080;3840;241;943;4082;3086;124;221;175;124;15;1807;3086;221!'));
Sembiance commented 2 years ago

Narrowed it down to this text.replace op: "\u001b[11;0;3549;3080;3840;241;943;4082;3086;124;221;175;124;15;1807;3086;221!".replace(/^\x1b\[((?:\d{1,3};?)+|)m/, v => "hi")

Sembiance commented 2 years ago

For anyone else experiencing this, you can se the following v8 flag to fix the problem: --enable-experimental-regexp-engine-on-excessive-backtracks