mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-02-12 11:12:38 +02:00
- Remove all [ConEMU OSC commands](https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC) from the output of Forgejo action logs when rendering. - The regex is constructed as followed: Match the prefix `ESC ] 9 ;`. Then matches any number of digits, then match everything up to and including `ST` (this is either `ESC\` or `BELL`). - Resolves forgejo/forgejo#9244 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9875 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
30 lines
1.8 KiB
JavaScript
30 lines
1.8 KiB
JavaScript
import {renderAnsi} from './ansi.js';
|
|
|
|
test('renderAnsi', () => {
|
|
expect(renderAnsi('abc')).toEqual('abc');
|
|
expect(renderAnsi('abc\n')).toEqual('abc');
|
|
expect(renderAnsi('abc\r\n')).toEqual('abc');
|
|
expect(renderAnsi('\r')).toEqual('');
|
|
expect(renderAnsi('\rx\rabc')).toEqual('x\nabc');
|
|
expect(renderAnsi('\rabc\rx\r')).toEqual('abc\nx');
|
|
expect(renderAnsi('\x1b[30mblack\x1b[37mwhite')).toEqual('<span class="ansi-black-fg">black</span><span class="ansi-white-fg">white</span>'); // unclosed
|
|
expect(renderAnsi('<script>')).toEqual('<script>');
|
|
expect(renderAnsi('\x1b[1A\x1b[2Ktest\x1b[1B\x1b[1A\x1b[2K')).toEqual('test');
|
|
expect(renderAnsi('\x1b[1A\x1b[2K\rtest\r\x1b[1B\x1b[1A\x1b[2K')).toEqual('test');
|
|
expect(renderAnsi('\x1b[1A\x1b[2Ktest\x1b[1B\x1b[1A\x1b[2K')).toEqual('test');
|
|
expect(renderAnsi('\x1b[1A\x1b[2K\rtest\r\x1b[1B\x1b[1A\x1b[2K')).toEqual('test');
|
|
|
|
// treat "\033[0K" and "\033[0J" (Erase display/line) as "\r", then it will be covered to "\n" finally.
|
|
expect(renderAnsi('a\x1b[Kb\x1b[2Jc')).toEqual('a\nb\nc');
|
|
expect(renderAnsi('\x1b[48;5;88ma\x1b[38;208;48;5;159mb\x1b[m')).toEqual(`<span style="background-color:rgb(135,0,0)">a</span><span style="background-color:rgb(175,255,255)">b</span>`);
|
|
|
|
expect(renderAnsi('\x1b]9;4;0\x07')).toEqual('');
|
|
expect(renderAnsi('\x1b]9;4;1;25\x07compiling main.zig')).toEqual('compiling main.zig');
|
|
expect(renderAnsi('\x1b]9;4;1;25\x1b\\compiling main.zig')).toEqual('compiling main.zig');
|
|
expect(renderAnsi('\x1b]9;4;3\x07waiting...')).toEqual('waiting...');
|
|
expect(renderAnsi('\x1b]9;1;500\x07sleeping...')).toEqual('sleeping...');
|
|
expect(renderAnsi('\x1b]9;4;3\x07waiting...\x1b]9;4;3\x07')).toEqual('waiting...');
|
|
expect(renderAnsi('\x1b]9;12\x07')).toEqual('');
|
|
expect(renderAnsi('\x1b]9;4;1;25\x07\x1bMcompiling main.zig')).toEqual('compiling main.zig');
|
|
});
|