Skip to content

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

Closed

Description

@voltcrash

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 47f2c8d. 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:

{"requested":"report.txt ","directRead":"ordinary file","rpcRead":"ordinary file","ordinaryAfterSave":"edited","spacedAfterSave":"whitespace file"}
{"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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions