-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
cargo run
cannot accept non-unicode arguments
#2511
Comments
You might want to try |
Oh I hadn't tried that. But it does look like I get the same result:
|
cc docopt/docopt.rs#152 and @BurntSushi, unfortunately this is a limitation of the underlying docopt library that Cargo is currently using. |
Now that being said I think we're also storing |
Yeah, docopt should grow support for this. The arg parser itself is written to work on |
This issue still seems valid in September 2018, after cargo switched to a different flag parsing library (clap). // main.rs
fn main() {
for input in std::env::args_os().skip(1) {
println!("input: {}", input.to_str().unwrap_or("<not a UTF-8 path>"));
}
} $ cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
$ ./target/debug/example test $(printf '\xff')
input: "test"
input: "<not a UTF-8 path>"
$ cargo run -- test $(printf '\xff')
thread 'main' panicked at 'unexpected invalid UTF-8 code point', libcore/option.rs:989:5
note: Run with `RUST_BACKTRACE=1` for a backtrace. |
… r=alexcrichton Pass OsStr/OsString args through to the process spawned by cargo run. This is intended to fix #2511, allowing non-UTF8 arguments to be passed through from cargo run to the spawned process. I was not sure whether the interface of cargo::ops needs to remain unchanged - I assume it does, so I added cargo::ops::run_os() taking &[OsString], and retained cargo::ops::run() with its current signature. If it's ok to change the internal cargo API then it may be better to just pass &[OsString] to run(). I have not tried to pass through OsStr/OsString to other places that could reasonably use them. Just one test added covering this path. It is restricted to `cfg(unix)` due to use of `std::os::unix::ffi::OsStrExt`. This is my first pull request so I expect there will be changes needed to make this mergeable.
Say I write a small program that just prints its args:
Because it uses
args_os()
instead ofargs()
, this program can handle command line args that aren't valid unicode. However,cargo run
chokes:I have to invoke the binary directly to test the program:
Does Cargo need to inspect the command line args at all? It not, it would be nice if it didn't require them to be utf8.
The text was updated successfully, but these errors were encountered: