Skip to content

fix(core): decide batch files the way std does - #4498

Closed
KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:fix/batch-detection-trailing-dots
Closed

KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:fix/batch-detection-trailing-dots

Conversation

@KuSh

@KuSh KuSh commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

On Windows, child_arg leaves the arguments of a batch file on std's encoder, since cmd.exe parses them by its own rules. is_batch_program decided that from the extension of the program name as given, while std decides it from the path Windows resolves: GetFullPathNameW drops trailing dots and spaces and folds . and .., and std then checks for a .bat/.cmd suffix (a verbatim \\?\ or \??\ path is checked as written). This makes rtk ask the same question: resolve with std::path::absolute, which is that call, then apply std's suffix test.

Behaviour change (Windows)

  • A program given as x.bat., x.bat , x.bat\. or a file named .cmd is now treated as the batch file std runs, so its quoted arguments stay on std's encoder.

Test plan

  • has_batch_suffix (std's suffix test) is asserted on every platform.
  • Windows: test_child_arg_leaves_batch_shims_on_stds_encoding now covers x.bat., x.bat , x.bat. ., x.bat\. and .cmd; test_batch_program_follows_the_path_windows_resolves covers x.bat\.., verbatim \\?\ and \??\ paths, and x.exe.
  • cargo fmt --all -- --check, cargo clippy --all-targets and cargo test --all pass on Linux; a Windows cargo check --all-targets passes.

🤖 Generated with Claude Code

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working core windows labels Oct 9, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes how rtk detects batch files (.bat/.cmd) on Windows for the purpose of deciding whether to leave arguments on std's encoder. Instead of checking the extension of the raw program name, it now resolves the path the same way Windows/std does (via std::path::absolute, with special-casing for verbatim \?\ and ??\ prefixes) before checking the suffix, fixing cases like trailing dots/spaces or path traversal components.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

std runs a program through cmd.exe as a batch file when the path Windows
resolves it to ends in `.bat` or `.cmd`: GetFullPathNameW drops trailing
dots and spaces and folds `.` and `..`, and a verbatim path is tested as
written. `is_batch_program` read the extension of the name as given, so
`x.bat.`, `x.bat `, `x.bat\.` or a file named `.cmd` were not treated as
the batch files std runs. It now resolves the path with
`std::path::absolute`, the same call, and applies std's suffix test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@KuSh

KuSh commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favour of #4103, which now carries this change. #4103 replaces is_batch_program in src/core/utils.rs with ChildCommand's own check, so this fix moved there: a program is a batch file when the path Windows resolves ends in .bat or .cmd, and a verbatim \\?\ or \??\ path is tested as written. The tests came along too: a_batch_suffix_is_matched_as_std_matches_it on every platform, and the Windows decision and encoding tests over x.bat., x.bat\., x.bat with a trailing space and .cmd.

@KuSh KuSh closed this Oct 16, 2026
@KuSh
KuSh deleted the fix/batch-detection-trailing-dots branch December 1, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant