The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 12:00 UTC
fix(composer): copied context with an apostrophe survives the HTML clipboard (#21537)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
MarcoDotIO committed
Oct 30, 2026 at 16:27 UTC
dcf051e861f0ae9fd52e2376150da0b1aa5aaa06
2 files changed
+29
-1
packages/shared/src/composerContextClipboard.test.ts
+26
@@ -76,6 +76,32 @@ describe("composerContextClipboard", () => {
76
).toBeNull();
77
expect(decodeComposerContextClipboardHtml("<p>Ordinary clipboard</p>")).toBeNull();
78
});
79
+ it("round-trips context whose text contains an apostrophe", () => {
80
+ const raw = JSON.stringify({
81
+ version: 1,
82
+ source: { environmentId: "env-1" },
83
+ records: [
84
+ {
85
+ version: 1,
86
+ kind: "terminal",
87
+ contextId: "terminal",
88
+ label: "Build",
89
+ terminalId: "main",
90
+ terminalLabel: "Main",
91
+ lineStart: 1,
92
+ lineEnd: 1,
93
+ text: "error: can't find module",
94
+ },
95
+ ],
96
+ });
97
+ const html = encodeComposerContextClipboardHtml("error: can't find module", raw);
98
+ expect(decodeComposerContextClipboardHtml(html)).toEqual(JSON.parse(raw));
99
+ expect(
100
+ decodeComposerContextClipboardHtml(
101
+ `<pre data-t3-context-fragment='${encodeURIComponent(raw).replaceAll("'", "%27")}'>x</pre>`,
102
+ ),
103
+ ).toEqual(JSON.parse(raw));
104
+ });
105
it("accepts a large non-ASCII fragment through the HTML attribute", () => {
106
// CJK code units expand to nine encoded characters despite fitting the fragment limit.
107
const raw = JSON.stringify({
packages/shared/src/composerContextClipboard.ts
+3
-1
@@ -35,7 +35,9 @@ export function decodeComposerContextClipboardHtml(
35
): ComposerContextClipboardFragment | null {
36
// Percent encoding can expand each UTF-16 code unit to nine characters.
37
if (!html || html.length > MAX_FRAGMENT_CHARS * 9 + HTML_WRAPPER_SLACK_CHARS) return null;
38
- const encoded = /data-t3-context-fragment=["']([^"']+)["']/.exec(html)?.[1];
38
+ // `encodeURIComponent` leaves `'` as is, so each quote style must end only at its own quote.
39
+ const match = /data-t3-context-fragment=(?:"([^"]+)"|'([^']+)')/.exec(html);
40
+ const encoded = match?.[1] ?? match?.[2];
41
if (!encoded) return null;
42
try {
43
return decodeComposerContextFragment(decodeURIComponent(encoded));