Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/tui/src/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export function createClipboardAdapter(clipboard: CoreClipboardService): OwnedCl
throw new Error(`Unexpected clipboard MIME type: ${result.representation.mimeType}`)
},
async write(text) {
const result = await clipboard.writeText(text, {
// Host clipboards reject NUL characters (e.g. from shell tool output);
// omit them so a single stray byte cannot fail the whole copy.
const result = await clipboard.writeText(text.replaceAll("\0", ""), {
destination: "all-available",
selection: "clipboard",
})
Expand Down
12 changes: 12 additions & 0 deletions packages/tui/test/clipboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ test("uses all available routes but skips the process host remotely", async () =
expect(writes).toEqual({ host: 0, terminal: 1 })
})

test("omits NUL characters that host clipboards cannot carry", async () => {
const writes: [string, ClipboardWriteOptions][] = []
const clipboard = createClipboardAdapter(
coreClipboard({
onWrite: (text, input) => writes.push([text, input]),
}),
)

await clipboard.write("a\0b\0")
expect(writes).toEqual([["ab", { destination: "all-available", selection: "clipboard" }]])
})

test("rejects only when no clipboard route accepted the write", async () => {
const writes: [string, ClipboardWriteOptions][] = []
const failure = new Error("native clipboard failed")
Expand Down
Loading