Skip to content

Commit eb357f1

Browse files
authored
fix(tui): strip NUL characters before clipboard writes (#48337)
1 parent 573d769 commit eb357f1

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎packages/tui/src/clipboard.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export function createClipboardAdapter(clipboard: CoreClipboardService): OwnedCl
5151
throw new Error(`Unexpected clipboard MIME type: ${result.representation.mimeType}`)
5252
},
5353
async write(text) {
54-
const result = await clipboard.writeText(text, {
54+
// OpenTUI rejects NUL before any destination; host clipboard text cannot contain it.
55+
const result = await clipboard.writeText(text.replaceAll("\0", ""), {
5556
destination: "all-available",
5657
selection: "clipboard",
5758
})

‎packages/tui/test/clipboard.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ test("uses all available routes but skips the process host remotely", async () =
102102
expect(writes).toEqual({ host: 0, terminal: 1 })
103103
})
104104

105+
test("removes NUL characters before writing", async () => {
106+
const writes: string[] = []
107+
const clipboard = createClipboardAdapter(
108+
coreClipboard({
109+
onWrite: (text) => writes.push(text),
110+
}),
111+
)
112+
113+
expect(await clipboard.write("before\0after")).toBeUndefined()
114+
expect(await clipboard.write("clean")).toBeUndefined()
115+
expect(writes).toEqual(["beforeafter", "clean"])
116+
})
117+
105118
test("rejects only when no clipboard route accepted the write", async () => {
106119
const writes: [string, ClipboardWriteOptions][] = []
107120
const failure = new Error("native clipboard failed")

0 commit comments

Comments
 (0)