deno
caf69f89 - fix(info): normalize trailing spaces in file path args on Windows (#35008)

Commit
164 days ago
fix(info): normalize trailing spaces in file path args on Windows (#35008) On Windows, a trailing space (or dot) in a file path argument such as `deno info ".\foo.tsx "` was percent-encoded into the module specifier (`foo.tsx%20`). The low-level Windows filesystem APIs still open the file (Win32 trims trailing spaces and dots when opening files), but the trailing `%20` caused the media type to be misdetected — e.g. `TypeScript` instead of `TSX` — producing a confusing parse error on otherwise valid JSX/TSX files: ``` deno info ".\tsx.tsx " error: The module's source code could not be parsed: Expected ';', got '!' at file:///C:/.../tsx.tsx%20:4:21 ``` On Linux/macOS the same command fails cleanly with `module could not be found` (a trailing space is a significant, distinct file name), so the behavior was inconsistent across platforms. ## Fix Normalize file path arguments the same way the Windows filesystem does, by stripping trailing spaces and dots from the final path component before building the specifier (`cli/util/path.rs::strip_windows_trailing_chars`, wired through a small `resolve_url_or_path_normalized` wrapper). URL arguments (anything with a URI scheme) are passed through unchanged. This is a no-op on non-Windows platforms, where trailing whitespace in a file name is significant. After the fix, `deno info ".\tsx.tsx "` reports `type: TSX` and resolves dependencies normally. ## Scope The wrapper is wired into the commands that resolve a single argv path string directly through `resolve_url_or_path` — `run`/`serve`/`compile`/`info` plus `--preload`/`--require`. That is where the exact `%20` media-type symptom reproduces. Other subcommands (`check`, `doc`, `test`, `bundle`, `cache`) resolve files through the file collector / glob expansion rather than `resolve_url_or_path`, so they don't hit the same code path. A fully uniform fix would live one layer deeper (in `deno_path_util`'s path→URL conversion), but that is an external crate; keeping the normalization in the CLI wrapper covers the reported case without reaching across repos. This can be broadened later if the same symptom is reported for the collector-based commands. Two sibling direct call sites are intentionally left unnormalized, as neither is the reported symptom: `cli/tools/run/mod.rs` (the eszip `entrypoint#paths` run path, a special case) and `cli/tools/compile.rs`'s `resolve_compile_executable_output_path` (only infers the output binary name; the actual compile module still resolves through the normalized `args/mod.rs` path). ## Test Added `tests/specs/info/jsx_trailing_space_windows` (gated with `"if": "windows"`, since the normalization is a no-op elsewhere), a `#[cfg(windows)]` unit test for `strip_windows_trailing_chars`, and a cross-platform unit test asserting URL arguments bypass normalization (locking in the scheme guard). Closes #30585 Closes denoland/divybot#537 --------- Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
Author
Parents
Loading