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 21, 18:30 UTC
fix(server): preserve filename whitespace when reading and saving files (#29314)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Lakshmi Tanmay committed
Nov 13, 2026 at 03:38 UTC
cbf9e26bc6a63906cae5a0d0f673a61b03b2d06b
7 files changed
+111
-25
apps/server/src/project/ProjectFaviconResolver.test.ts
+11
@@ -201,6 +201,17 @@ it.layer(layerTest)("ProjectFaviconResolverLive", (it) => {
201
202
expect(resolved).not.toBeNull();
203
expect(resolved).toBe((yield* Path.Path).join(cwd, "public", "brand", "logo.svg"));
204
+
205
+ const paddedCwd = yield* makeTempDir;
206
+ yield* writeTextFile(
207
+ paddedCwd,
208
+ "index.html",
209
+ '<link rel="icon" href=" brand/custom.svg ">',
210
+ );
211
+ yield* writeTextFile(paddedCwd, "brand/custom.svg", "<svg>custom</svg>");
212
+ expect(yield* resolver.resolvePath(paddedCwd)).toBe(
213
+ (yield* Path.Path).join(paddedCwd, "brand", "custom.svg"),
214
+ );
215
}),
216
);
217
apps/server/src/project/ProjectFaviconResolver.ts
+2
-1
@@ -144,7 +144,8 @@ export const make = Effect.gen(function* () {
144
const projectFileLoader = yield* T3ProjectFileLoader.T3ProjectFileLoader;
145
146
const resolveIconHref = (href: string): ReadonlyArray<string> => {
147
- const clean = href.replace(/^\//, "");
147
+ // Browsers strip surrounding whitespace from URL attributes; file paths keep theirs.
148
+ const clean = href.trim().replace(/^\//, "");
149
return [path.join("public", clean), clean];
150
};
151
apps/server/src/workspace/WorkspaceFileSystem.test.ts
+42
-10
@@ -43,6 +43,11 @@ const injectShortReads = Effect.fn("injectShortReads")(function* (target: string
43
yield* Effect.addFinalizer(() => Effect.sync(() => open.mockImplementation(native.open)));
44
});
45
46
+const whitespaceFilePaths =
47
+ HostProcess.Platform.defaultValue() === "win32"
48
+ ? [" report.txt"]
49
+ : [" report.txt", "report.txt ", "\treport.txt\t", " "];
50
+
51
const UNKNOWN_WORKSPACE_PREFIX = "t3code-unknown-workspace-";
52
const layerKnownWorkspacesTest = Layer.mock(KnownWorkspaces.KnownWorkspaces)({
53
assertContains: (cwd) =>
@@ -196,6 +201,14 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
201
byteLength: 26,
202
truncated: false,
203
});
204
+
205
+ yield* writeTextFile(cwd, "report.txt", "ordinary file");
206
+ for (const relativePath of whitespaceFilePaths) {
207
+ yield* writeTextFile(cwd, relativePath, "whitespace file");
208
+ const read = yield* workspaceFileSystem.readFile({ cwd, relativePath });
209
+ expect(read.contents).toBe("whitespace file");
210
+ expect(read.relativePath).toBe(relativePath);
211
+ }
212
}),
213
);
214
@@ -250,6 +263,14 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
263
byteLength: 9,
264
truncated: false,
265
});
266
+
267
+ for (const relativePath of whitespaceFilePaths) {
268
+ yield* writeTextFile(outsideDir, relativePath, "whitespace file");
269
+ const requestedPath = path.join(outsideDir, relativePath);
270
+ const read = yield* workspaceFileSystem.readFile({ cwd, relativePath: requestedPath });
271
+ expect(read.contents).toBe("whitespace file");
272
+ expect(read.relativePath).toBe(requestedPath);
273
+ }
274
}),
275
);
276
@@ -560,6 +581,21 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
581
expect(yield* fileSystem.readFileString(path.join(cwd, "src/main.ts"))).toBe(
582
"export const edited = true;\n",
583
);
584
+
585
+ yield* writeTextFile(cwd, "report.txt", "ordinary file");
586
+ for (const relativePath of whitespaceFilePaths) {
587
+ yield* writeTextFile(cwd, relativePath, "whitespace file");
588
+ const written = yield* workspaceFileSystem.writeFile({
589
+ cwd,
590
+ relativePath,
591
+ contents: "edited",
592
+ });
593
+ expect(yield* fileSystem.readFileString(path.join(cwd, "report.txt"))).toBe(
594
+ "ordinary file",
595
+ );
596
+ expect(yield* fileSystem.readFileString(path.join(cwd, relativePath))).toBe("edited");
597
+ expect(written.relativePath).toBe(relativePath);
598
+ }
599
}).pipe(
600
Effect.provide(
601
Layer.fresh(WorkspaceFileSystem.layer).pipe(
@@ -582,17 +618,13 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
618
const path = yield* Path.Path;
619
const fileSystem = yield* FileSystem.FileSystem;
620
585
- const error = yield* workspaceFileSystem
586
- .writeFile({
587
- cwd,
588
- relativePath: "../escape.md",
589
- contents: "# nope\n",
590
- })
591
- .pipe(Effect.flip);
621
+ for (const relativePath of ["../escape.md", "../escape.md ", " folder/../../escape.md"]) {
622
+ const error = yield* workspaceFileSystem
623
+ .writeFile({ cwd, relativePath, contents: "# nope\n" })
624
+ .pipe(Effect.flip);
625
593
- expect(error.message).toContain(
594
- "Workspace file path must be relative to the project root: ../escape.md",
595
- );
626
+ expect(error).toBeInstanceOf(WorkspacePaths.WorkspacePathOutsideRootError);
627
+ }
628
629
const escapedPath = path.resolve(cwd, "..", "escape.md");
630
const escapedStat = yield* fileSystem
apps/server/src/workspace/WorkspaceFileSystem.ts
+1
-1
@@ -227,7 +227,7 @@ export const make = Effect.gen(function* () {
227
const resolveReadTarget = Effect.fn("WorkspaceFileSystem.resolveReadTarget")(function* (
228
input: ProjectReadFileInput,
229
) {
230
- const requestedPath = input.relativePath.trim();
230
+ const requestedPath = input.relativePath;
231
const hostPath = requestedPath.startsWith("~/")
232
? expandHomePath(requestedPath, yield* HostProcess.HomeDirectory)
233
: requestedPath;
apps/server/src/workspace/WorkspacePaths.ts
+2
-3
@@ -175,15 +175,14 @@ const make = Effect.gen(function* () {
175
176
const resolveRelativePathWithinRoot: WorkspacePaths["Service"]["resolveRelativePathWithinRoot"] =
177
Effect.fn("WorkspacePaths.resolveRelativePathWithinRoot")(function* (input) {
178
- const normalizedInputPath = input.relativePath.trim();
179
- if (path.isAbsolute(normalizedInputPath)) {
178
+ if (path.isAbsolute(input.relativePath)) {
179
return yield* new WorkspacePathOutsideRootError({
180
workspaceRoot: input.workspaceRoot,
181
relativePath: input.relativePath,
182
});
183
}
184
186
- const absolutePath = path.resolve(input.workspaceRoot, normalizedInputPath);
185
+ const absolutePath = path.resolve(input.workspaceRoot, input.relativePath);
186
// Only the host separator becomes `/`: on POSIX `\` is a file name character.
187
const relativeToRoot = path
188
.relative(input.workspaceRoot, absolutePath)
packages/contracts/src/project.test.ts
+43
@@ -10,12 +10,16 @@ import {
10
ReceivedProjectIcon,
11
StoredProjectIcon,
12
ProjectReadFileError,
13
+ ProjectReadFileInput,
14
+ ProjectReadFileResult,
15
ProjectCreatePayload,
16
ProjectUpdatePayload,
17
ProjectMutation,
18
ProjectSearchContentsError,
19
ProjectSearchEntriesError,
20
ProjectWriteFileError,
21
+ ProjectWriteFileInput,
22
+ ProjectWriteFileResult,
23
} from "./project.ts";
24
25
const decodeProjectCreatePayload = Schema.decodeUnknownSync(ProjectCreatePayload);
@@ -23,6 +27,45 @@ const decodeProjectUpdatePayload = Schema.decodeUnknownSync(ProjectUpdatePayload
27
const decodeProjectMutation = Schema.decodeUnknownSync(ProjectMutation);
28
29
describe("project RPC errors", () => {
30
+ it("keeps whitespace in file paths across the wire", () => {
31
+ const roundTrip = <S extends Schema.Codec<unknown, unknown>>(schema: S, value: S["Type"]) =>
32
+ Schema.decodeUnknownSync(schema)(Schema.encodeSync(schema)(value));
33
+
34
+ for (const relativePath of [" ", " report.txt", "report.txt\t"]) {
35
+ const cwd = "/workspace";
36
+ const resolvedPath = `${cwd}/${relativePath}`;
37
+ expect(roundTrip(ProjectReadFileInput, { cwd, relativePath }).relativePath).toBe(
38
+ relativePath,
39
+ );
40
+ expect(
41
+ roundTrip(ProjectWriteFileInput, { cwd, relativePath, contents: "" }).relativePath,
42
+ ).toBe(relativePath);
43
+ expect(
44
+ roundTrip(ProjectReadFileResult, {
45
+ relativePath,
46
+ contents: "",
47
+ byteLength: 0,
48
+ truncated: false,
49
+ }).relativePath,
50
+ ).toBe(relativePath);
51
+ expect(roundTrip(ProjectWriteFileResult, { relativePath }).relativePath).toBe(relativePath);
52
+ for (const FileError of [ProjectReadFileError, ProjectWriteFileError]) {
53
+ const error = new FileError({
54
+ cwd,
55
+ relativePath,
56
+ failure: "operation_failed",
57
+ resolvedPath,
58
+ operationPath: resolvedPath,
59
+ });
60
+ expect(roundTrip(FileError, error)).toMatchObject({
61
+ relativePath,
62
+ resolvedPath,
63
+ operationPath: resolvedPath,
64
+ });
65
+ }
66
+ }
67
+ });
68
+
69
it("derives stable messages from structured request context while retaining causes", () => {
70
const cause = new Error("sensitive platform detail");
71
const searchError = new ProjectSearchEntriesError({
packages/contracts/src/project.ts
+10
-10
@@ -438,14 +438,14 @@ export class ProjectListEntriesError extends Schema.TaggedError<ProjectListEntri
438
export const ProjectReadFileInput = Schema.Struct({
439
cwd: TrimmedNonEmptyString,
440
// Workspace-relative or absolute host path; only workspace-relative paths are writable.
441
- relativePath: TrimmedNonEmptyString.check(Schema.isMaxLength(PROJECT_READ_FILE_PATH_MAX_LENGTH)),
441
+ relativePath: Schema.NonEmptyString.check(Schema.isMaxLength(PROJECT_READ_FILE_PATH_MAX_LENGTH)),
442
// Optional files can be absent without failing the read.
443
allowMissing: Schema.optional(Schema.Boolean),
444
});
445
export type ProjectReadFileInput = typeof ProjectReadFileInput.Type;
446
447
export const ProjectReadFileResult = Schema.Struct({
448
- relativePath: TrimmedNonEmptyString,
448
+ relativePath: Schema.NonEmptyString,
449
contents: Schema.String,
450
byteLength: NonNegativeInt,
451
truncated: Schema.Boolean,
@@ -490,12 +490,12 @@ export class ProjectReadFileError extends Schema.TaggedError<ProjectReadFileErro
490
"ProjectReadFileError",
491
{
492
cwd: Schema.optional(TrimmedNonEmptyString),
493
- relativePath: Schema.optional(TrimmedNonEmptyString),
493
+ relativePath: Schema.optional(Schema.NonEmptyString),
494
failure: Schema.optional(ProjectFileFailure),
495
- resolvedPath: Schema.optional(TrimmedNonEmptyString),
495
+ resolvedPath: Schema.optional(Schema.NonEmptyString),
496
resolvedWorkspaceRoot: Schema.optional(TrimmedNonEmptyString),
497
operation: Schema.optional(ProjectFileOperation),
498
- operationPath: Schema.optional(TrimmedNonEmptyString),
498
+ operationPath: Schema.optional(Schema.NonEmptyString),
499
message: TrimmedNonEmptyString,
500
cause: Schema.optional(Schema.Defect()),
501
},
@@ -513,13 +513,13 @@ export class ProjectReadFileError extends Schema.TaggedError<ProjectReadFileErro
513
514
export const ProjectWriteFileInput = Schema.Struct({
515
cwd: TrimmedNonEmptyString,
516
- relativePath: TrimmedNonEmptyString.check(Schema.isMaxLength(PROJECT_WRITE_FILE_PATH_MAX_LENGTH)),
516
+ relativePath: Schema.NonEmptyString.check(Schema.isMaxLength(PROJECT_WRITE_FILE_PATH_MAX_LENGTH)),
517
contents: Schema.String,
518
});
519
export type ProjectWriteFileInput = typeof ProjectWriteFileInput.Type;
520
521
export const ProjectWriteFileResult = Schema.Struct({
522
- relativePath: TrimmedNonEmptyString,
522
+ relativePath: Schema.NonEmptyString,
523
});
524
export type ProjectWriteFileResult = typeof ProjectWriteFileResult.Type;
525
@@ -555,12 +555,12 @@ export class ProjectWriteFileError extends Schema.TaggedError<ProjectWriteFileEr
555
"ProjectWriteFileError",
556
{
557
cwd: Schema.optional(TrimmedNonEmptyString),
558
- relativePath: Schema.optional(TrimmedNonEmptyString),
558
+ relativePath: Schema.optional(Schema.NonEmptyString),
559
failure: Schema.optional(ProjectFileFailure),
560
- resolvedPath: Schema.optional(TrimmedNonEmptyString),
560
+ resolvedPath: Schema.optional(Schema.NonEmptyString),
561
resolvedWorkspaceRoot: Schema.optional(TrimmedNonEmptyString),
562
operation: Schema.optional(ProjectFileOperation),
563
- operationPath: Schema.optional(TrimmedNonEmptyString),
563
+ operationPath: Schema.optional(Schema.NonEmptyString),
564
message: TrimmedNonEmptyString,
565
cause: Schema.optional(Schema.Defect()),
566
},