8000 Use raw_arg on Windows to fix handling of spaces in commands by jhasse · Pull Request #2689 · casey/just · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use raw_arg on Windows to fix handling of spaces in commands #2689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jhasse
Copy link
@jhasse jhasse commented Mar 31, 2025

On Windows Rust escapes arguments for security reasons, but since we are passing an argument to a shell (i.e. can execute arbitrary code anyway), this should be disabled in order to correctly support quoting and spaces in commands.

https://doc.rust-lang.org/std/process/index.html#windows-argument-splitting

Fixes #1639.

On Windows Rust escapes arguments for security reasons, but since we are
passing an argument to a shell (i.e. can execute arbitrary code anyway),
this should be disabled in order to correctly support quoting and spaces
in commands.

https://doc.rust-lang.org/std/process/index.html#windows-argument-splitting

Fixes casey#1639.
Copy link
Owner
@casey casey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you for the PR!

  1. Can you add a test for this? I want to make sure I understand the issue being fixed, and since it's subtle, make sure that there isn't a regression in the future.
  2. Should we use this for all arguments? If not, why not?
  3. See comments.

@jhasse
Copy link
Author
jhasse commented Apr 1, 2025
  1. I'm not good at Rust, but I can try :) In which file would such a test go and is there a similar test I can look at?
  2. Hm ... yes I think so, although I can't think of a scenario where it would matter. Maybe when someone has a shell with a parameter that needs spaces. I guess 99% of the time the shell parameter is /c or something similar though.

…n for raw_arg

Co-authored-by: Casey Rodarmor <casey@rodarmor.com>
@casey
Copy link
Owner
casey commented Apr 3, 2025

@jhasse The test can go in tests/windows.rs. I don't understand what the issue is myself, since windows argument handling seems extremely arcane to me, so I can't give much guidance about what an existing test to copy is. Check out any test that uses the Test::new() constructor to create a new test. If 99% of the time the shell parameter doesn't contain a space, that means 1% of the time it will break, which is too often ;) So we should definitely do whatever is the right thing.

@jhasse
Copy link
Author
jhasse commented Apr 5, 2025

I've tried to run the test in windows.rs but it failed:

› cargo test bare_bash_in_shebang
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.14s
     Running unittests src\lib.rs (target\debug\deps\just-601a7f99ed7e8a65.exe)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 499 filtered out; finished in 0.00s

     Running tests\lib.rs (target\debug\deps\integration-a255eaaa12765568.exe)

running 1 test
test windows::bare_bash_in_shebang ... FAILED

failures:

---- windows::bare_bash_in_shebang stdout ----
Bad status: Diff < left / right > :
 Some(
<    127,
>    0,
 )

Bad stdout: Diff < left / right > :
>FOO
>

Bad stderr: Diff < left / right > :
</bin/bash: C:UsersjhasseAppDataLocalTempjust-cUgCqDdefault: No such file or directory
<error: Recipe `default` failed with exit code 127
<


thread 'windows::bare_bash_in_shebang' panicked at tests\windows.rs:14:6:
Output mismatch.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    windows::bare_bash_in_shebang

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 885 filtered out; finished in 0.12s

error: test failed, to rerun pass `--test integration`

Is there anything I need to set up on Windows to run the tests? Do I need to install Cygwin?

@casey
Copy link
Owner
casey commented Apr 5, 2025

Can you commit and push your failing test to the branch, so I can see it?

@jhasse
Copy link
Author
jhasse commented Apr 6, 2025

bare_bash_in_shebang was an existing test which I didn't touch, so there seems to be something fundamentally wrong with my setup.

I've pushed my attempt for a test for this issue.

@casey
Copy link
Owner
casey commented Apr 6, 2025

Nice, thank you! I think the issue is that && isn't valid syntax for cmd.exe, that's a bash-ism.

@jhasse
Copy link
Author
jhasse commented Apr 7, 2025

No, && works the same way as in bash: https://superuser.com/a/1695562/114883

@casey
Copy link
Owner
casey commented Apr 7, 2025

@jhasse TIL! Check out the test logs, I'm seeing some failures in the unit tests which I don't understand.

@jhasse
Copy link
Author
jhasse commented Apr 7, 2025

Hm ... me neither :(

I've tried setting RUST_BACKTRACE=1 to get a better understanding. No idea if that is the right way forward.

@casey
Copy link
Owner
casey commented Apr 7, 2025

I think that in order to fix this, you'll need to be able to run the tests locally, otherwise the debug loop will be really slow if you have to run the tests on CI. Are you set up to do Windows Rust development? I have a Windows laptop I use for stuff like this, but I'm pretty busy so I don't know when I'll be able to get it out to take a look.

@jhasse
Copy link
Author
jhasse commented Apr 7, 2025

I have a Windows setup, but the test fail, even on the master branch (see #2689 (comment)).

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.

Quoting problems on Windows
2 participants
0