The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): files with brackets in their names attach on Android (#28983)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 1, 2026 at 21:25 UTC
b12ab30950b7231c50410703befb922464292e8b
2 files changed
+33
-5
apps/mobile/src/lib/composerImages.test.ts
+31
-1
@@ -59,6 +59,19 @@ vi.mock("expo-file-system", () => ({
59
return files.get(this.uri)?.mimeType ?? "";
60
}
61
62
+ get size(): number | null {
63
+ const entry = files.get(this.uri);
64
+ return entry && !entry.deleted
65
+ ? Math.floor((entry.base64.replace(/=+$/, "").length * 3) / 4)
66
+ : null;
67
+ }
68
+
69
+ async copy(destination: { readonly uri: string }): Promise<void> {
70
+ const entry = files.get(this.uri);
71
+ if (!entry) throw new Error("missing file");
72
+ files.set(destination.uri, { ...entry });
73
+ }
74
+
75
async base64(): Promise<string> {
76
const entry = files.get(this.uri);
77
if (!entry || entry.deleted) {
@@ -98,6 +111,7 @@ vi.mock("expo-file-system", () => ({
111
112
create(): void {}
113
},
114
+ FileMode: { ReadOnly: "r", WriteOnly: "w" },
115
Paths: { document: "file:///documents" },
116
}));
117
@@ -105,7 +119,7 @@ vi.mock("./uuid", () => ({
119
uuidv4: () => "attachment-id",
120
}));
121
108
-import { convertPastedImagesToAttachments } from "./composerImages";
122
+import { convertPastedImagesToAttachments, persistComposerAttachmentFile } from "./composerImages";
123
124
describe("native pasted image cleanup", () => {
125
beforeEach(() => {
@@ -204,6 +218,22 @@ describe("native pasted image cleanup", () => {
218
});
219
});
220
221
+describe("persistComposerAttachmentFile", () => {
222
+ beforeEach(() => {
223
+ files.clear();
224
+ });
225
+
226
+ it("stores picked files under a name Android's java.net.URI accepts", async () => {
227
+ const source = "file:///cache/DocumentPicker/Report [draft].pdf";
228
+ files.set(source, { base64: "JVBERg==", deleted: false });
229
+
230
+ const fileUri = await persistComposerAttachmentFile(source, "Report [draft].pdf");
231
+
232
+ // expo-file-system encodes spaces and `%` but leaves `[`, `]`, `|` and `^` raw.
233
+ expect(fileUri.split("/").at(-1)).toMatch(/^[\w\-.!~*'();:@&=+$, %]+\.pdf$/);
234
+ });
235
+});
236
+
237
describe("composerStripAttachments", () => {
238
const image = {
239
id: "img-1",
apps/mobile/src/lib/composerImages.ts
+2
-4
@@ -127,10 +127,8 @@ export async function persistComposerAttachmentFile(
127
const { Directory, File, FileMode, Paths } = await import("expo-file-system");
128
const directory = new Directory(Paths.document, COMPOSER_ATTACHMENT_DIRECTORY);
129
directory.create({ idempotent: true, intermediates: true });
130
- const safeName =
131
- Array.from(name, (character) =>
132
- character === "/" || character === "\\" || character.charCodeAt(0) < 32 ? "-" : character,
133
- ).join("") || "file";
130
+ // Android's java.net.URI rejects characters expo-file-system leaves unencoded, such as `[` and `]`.
131
+ const safeName = name.replace(/[^\w. -]/g, "-") || "file";
132
const destination = new File(directory, `${uuidv4()}-${safeName}`);
133
const source = new File(uri);
134
const sourceSize = source.size;