Skip to content

fix(windows): preserve backslashes before quotes in forced-quoted argv - #442

Merged
caomengxuan666 merged 2 commits into
unixwin:masterfrom
I-Want-ToBelieve:codex/fix-windows-argument-quoting
Oct 6, 2026
Merged

caomengxuan666 merged 2 commits into
unixwin:masterfrom
I-Want-ToBelieve:codex/fix-windows-argument-quoting

Conversation

@I-Want-ToBelieve

@I-Want-ToBelieve I-Want-ToBelieve commented Oct 5, 2026 •

Copy link
Copy Markdown

Windows arguments containing *, ?, or [ use forced quoting to prevent a child CRT from expanding literal wildcards. When such an argument also contains a backslash immediately before a double quote, the serializer preserves only the original backslashes plus one escape. This changes quoting state in the native child's command-line parser, corrupting or splitting the argument. A single-quoted node -e program with a JavaScript array literal reproduces the failure in Niubash 1.3.3.

Emit 2n + 1 backslashes before embedded quotes, preserve ordinary backslash runs, and keep doubling trailing runs. The wildcard/MSYS admission rules stay as they are. This corrects the Windows transport boundary shared by native and MSYS/Cygwin children.

Closes unixwin/niubash#197.

Regression coverage

Add a native-child round-trip test using this crate's libtest executable as an argv observer, without Node, PowerShell, or a new dependency. It checks the reported JavaScript argument, all three wildcard triggers, zero through four backslashes before quotes, trailing runs, Unicode, and a final argument that catches quote-state leakage. The test failed against the old serializer and passes with this patch.

Validation

  • cargo fmt --check and git diff --check passed.
  • cargo test --lib --locked: 624 passed, with the host's WINUXSH_SHELL_PATH_STYLE / __RUBASH_PATH_STYLE unset in the test environment.
  • Existing rubash_to_powershell_preserves_native_argument_literals CLI regression passed.
  • Niubash cargo build --locked succeeded using this patched rubash checkout. Its freshly built executable ran the original complex node -e assertion successfully on Windows 10 Pro 19045 / Node v24.19.0.
  • WSL GNU Bash 5.3 differential validation was not run: this machine has no installed WSL distribution. This change is limited to Windows argv serialization; it does not change lexing, expansion, or carrier handling.

Contract references

  • Microsoft's Windows C command-line parsing rules specify the backslash/quote transport behavior.
  • GNU semantic traceability: the checked-out Bash reference's execute_cmd.c:5930 materializes the argument vector and execute_cmd.c:6126 shell_execve() passes it to execve at line 6133. The Rust implementation preserves that literal argument contract through Windows command-line serialization; no GNU implementation code is copied.

Emit 2n + 1 backslashes before embedded double quotes so wildcard-protected
arguments round-trip through the native child command-line parser. Keep
ordinary and trailing backslash handling intact.

Add a dependency-free native child argv regression and run it in Windows CI.
The regression fails before the fix and passes afterward. All 624 library
tests and the existing PowerShell argv contract pass; a freshly built Niubash
also passes the reported Node inline-code assertion.

GNU semantic reference: execute_cmd.c:5930 argument-vector construction,
execute_cmd.c:6126 shell_execve(), execve call at line 6133. This is a Windows
serialization correction, with no lexer/expansion or carrier changes. WSL
GNU Bash 5.3 differential validation was unavailable (no installed distro).

Refs unixwin/niubash#197
@arookieofc

Copy link
Copy Markdown
Member

Don't change ci.yml,Thanks!

Restore .github/workflows/ci.yml to the PR base as requested by the
maintainer. Keep the Windows argument serializer fix and native argv
regression tests in src/executor/path.rs.
@I-Want-ToBelieve

Copy link
Copy Markdown
Author

@a-rookie-of-C-language Thanks for the review! I've withdrawn all changes to .github/workflows/ci.yml and updated the PR description. The PR now contains only the Windows argument-quoting fix and its regression tests in src/executor/path.rs.

@caomengxuan666
caomengxuan666 merged commit 8d8c66a into unixwin:master Oct 6, 2026
6 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

@iwantobelieve Thanks for your contribution!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: wildcard-protected arguments corrupt backslashes before embedded quotes (node -e)

4 participants