[Bug]: Reading and saving filenames with whitespace targets another file#29313

opened9d agobyVvoltcrash

Area

apps/server and packages/contracts

Steps to reproduce

On Linux or macOS, in a known workspace:

  1. Create report.txt containing ordinary file and report.txt (one trailing space) containing whitespace file.
  2. Call projects.readFile with that workspace's cwd and relativePath: "report.txt ".
  3. Call projects.writeFile with the same path and contents: "edited".
  4. Read both files directly from disk. Repeat with " report.txt" (one leading space).

These are service/RPC reproductions; no file-tree or editor interaction is needed.

Expected behavior

The read returns whitespace file. The save changes only the explicitly requested whitespace filename, leaving report.txt unchanged.

Actual behavior

The read returns ordinary file. Saving overwrites report.txt, while the requested whitespace file retains its old contents.

ProjectReadFileInput/ProjectWriteFileInput and their success results trim the path during serialization. WorkspacePaths.resolveRelativePathWithinRoot and WorkspaceFileSystem.resolveReadTarget also trim it, so direct service calls reproduce the problem too.

Environment and version

Reproduced on Linux, Node v26.12.1, upstream main at 47f2c8d29e981c7723467efe137ee19e91df924e. Leading/trailing whitespace is valid in POSIX filenames; Windows has different filename restrictions.

Runtime evidence

A standalone run against the actual file service, with a temporary workspace and the read/write RPC codecs:

json
1{"requested":"report.txt ","directRead":"ordinary file","rpcRead":"ordinary file","ordinaryAfterSave":"edited","spacedAfterSave":"whitespace file"}
2{"requested":" report.txt","directRead":"ordinary file","rpcRead":"ordinary file","ordinaryAfterSave":"edited","spacedAfterSave":"whitespace file"}

This concerns read/save targeting and potential data loss, separate from the duplicate file-tree entry issue in closed PR #22847.