fix: Escape backticks in stdout and stderr

This commit is contained in:
Manabu Sakai 2024-03-10 13:30:00 +09:00
parent a75f1a3cce
commit 679784b708
3 changed files with 13 additions and 2 deletions

View file

@ -34,7 +34,8 @@ class OutputListener {
get contents () {
return this._buff
.map(chunk => chunk.toString())
.join('');
.join('')
.replace(/`/g, '\\`');
}
}

View file

@ -14,4 +14,13 @@ describe('output-listener', () => {
listen(Buffer.from('baz'));
expect(listener.contents).toEqual('foobarbaz');
});
it('escape backticks', () => {
const listener = new OutputListener();
const listen = listener.listener;
listen(Buffer.from('foo'));
listen(Buffer.from('`bar`'));
listen(Buffer.from('baz'));
expect(listener.contents).toEqual('foo\\`bar\\`baz');
});
});