[Bug]: Reading and saving filenames with whitespace targets another file#29313
Area
apps/server and packages/contracts
Steps to reproduce
On Linux or macOS, in a known workspace:
- Create
report.txtcontainingordinary fileandreport.txt(one trailing space) containingwhitespace file. - Call
projects.readFilewith that workspace'scwdandrelativePath: "report.txt ". - Call
projects.writeFilewith the same path andcontents: "edited". - 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:
| 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.