Skip to content

Commit 683e277

Browse files
fix: strip ANSI escape sequences in terminal command output
1 parent 366311e commit 683e277

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

sdk/src/__tests__/run-terminal-command.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,21 @@ describe('rewriteWindowsNulRedirects', () => {
6969
})
7070

7171
describe('BoundedOutputBuffer', () => {
72-
test('preserves output below the limit and strips terminal colors', () => {
72+
test('preserves output below the limit and strips terminal escape sequences', () => {
7373
const output = new BoundedOutputBuffer(100)
7474
output.append('\u001b[31')
7575
output.append('mhello\u001b[0m world')
7676

7777
expect(output.format()).toBe('hello world')
7878
})
7979

80+
test('strips cursor-control sequences', () => {
81+
const output = new BoundedOutputBuffer(100)
82+
output.append('before\u001b[2J\u001b[Hafter')
83+
84+
expect(output.format()).toBe('beforeafter')
85+
})
86+
8087
test('keeps a bounded prefix and suffix for oversized output', () => {
8188
const output = new BoundedOutputBuffer(100)
8289
output.append('start-' + 'x'.repeat(200) + '-end')

sdk/src/tools/run-terminal-command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
} from 'child_process'
99
import type { Readable } from 'stream'
1010

11-
import { stripColors } from '../../../common/src/util/string'
11+
import { stripAnsi } from '../../../common/src/util/string'
1212
import { getSystemProcessEnv } from '../env'
1313
import {
1414
createWindowsBashNotFoundError,
@@ -92,7 +92,7 @@ export class BoundedOutputBuffer {
9292
this.pendingColorSequence = incompleteColorSequence
9393
normalized = normalized.slice(0, -incompleteColorSequence.length)
9494
}
95-
normalized = stripColors(normalized)
95+
normalized = stripAnsi(normalized)
9696
if (!normalized) return
9797

9898
if (!this.truncated) {

0 commit comments

Comments
 (0)