Skip to content

Commit f4f4026

Browse files
committed
diamond: ignore OSC sequences in submitted terminal text
1 parent 6545704 commit f4f4026

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

packages/web/src/features/terminal-panel/__tests__/xterm-host.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,38 @@ describe('XtermHost', () => {
487487
);
488488
});
489489

490+
it('ignores OSC control sequences while buffering submitted text', async () => {
491+
const store = createStore();
492+
const sendTerminalInput = vi.fn().mockResolvedValue(undefined);
493+
494+
store.set(wsClientAtom, {
495+
sendTerminalInput,
496+
subscribe: vi.fn(() => () => {}),
497+
} as never);
498+
499+
render(
500+
<Provider store={store}>
501+
<XtermHost terminalId="osc-submit-terminal" workspaceId="test-workspace" />
502+
</Provider>
503+
);
504+
505+
const onDataCallback = mockTerminal.onData.mock.calls[0]?.[0];
506+
expect(onDataCallback).toBeTypeOf('function');
507+
508+
await onDataCallback?.('f');
509+
await onDataCallback?.('i');
510+
await onDataCallback?.('x');
511+
await onDataCallback?.('\x1b]10;rgb:e5/e5/e5\x07');
512+
await onDataCallback?.('\r');
513+
514+
expect(sendTerminalInput).toHaveBeenLastCalledWith(
515+
'osc-submit-terminal',
516+
new TextEncoder().encode('\r'),
517+
'submit',
518+
'fix'
519+
);
520+
});
521+
490522
it('buffers live output until replay finishes and drops overlapping bytes', async () => {
491523
const store = createStore();
492524
const replayChunk = new TextEncoder().encode('replay snapshot\n');

packages/web/src/features/terminal-panel/components/xterm-host.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ function consumeTerminalInputDraft(
5656

5757
if (char === '\x1b') {
5858
const remaining = data.slice(index);
59-
const escapeMatch = remaining.match(/^\x1b(?:\[[0-9;?]*[ -/]*[@-~]|O.|.)/);
59+
const escapeMatch = remaining.match(
60+
/^\x1b(?:\[[0-9;?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|P[\s\S]*?\x1b\\|[@-_])/
61+
);
6062
if (escapeMatch) {
6163
index += escapeMatch[0].length - 1;
6264
continue;

0 commit comments

Comments
 (0)