-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
Description
Say I write a small program that just prints its args:
fn main() {
for arg in std::env::args_os() {
println!("{:?}", arg);
}
}
Because it uses args_os()
instead of args()
, this program can handle command line args that aren't valid unicode. However, cargo run
chokes:
$ cargo run $(printf '\xff')
invalid unicode in argument: "\u{fffd}"
I have to invoke the binary directly to test the program:
$ ./target/debug/scratch $(printf '\xff')
"./target/debug/scratch"
"\u{fffd}"
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.
jakwings
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
jonas-schievink commentedon Mar 23, 2016
You might want to try
cargo run -- $(printf '\xff')
- without the--
, cargo parses the 0xff as an argument for cargo runoconnor663 commentedon Mar 23, 2016
Oh I hadn't tried that. But it does look like I get the same result:
alexcrichton commentedon Mar 23, 2016
cc docopt/docopt.rs#152 and @BurntSushi, unfortunately this is a limitation of the underlying docopt library that Cargo is currently using.
alexcrichton commentedon Mar 23, 2016
Now that being said I think we're also storing
Vec<String>
in a few places instead ofVec<OsString>
, so there's also changes to be had on the Cargo side as wellBurntSushi commentedon Mar 23, 2016
Yeah, docopt should grow support for this. The arg parser itself is written to work on
&str
, so there are a fair amount of guts that will have to change, but shouldn't be too bad.johnbartholomew commentedon Sep 8, 2018
This issue still seems valid in September 2018, after cargo switched to a different flag parsing library (clap).
Auto merge of #6849 - johnbartholomew:issue-2511-cargo-non-utf8-args,…