mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 11:44:28 +00:00
Fix make_command_line to handle Unicode correctly
Previously, make_command_line iterates over each u8 in the string and then appends them as chars, so any non-ASCII string will get horribly mangled by this function. This fix should allow Unicode arguments to work correctly in native::io::process::spawn.
This commit is contained in:
parent
e12aeb39bc
commit
b6cce7ea54
@ -409,16 +409,17 @@ fn make_command_line(prog: &str, args: &[~str]) -> ~str {
|
||||
if quote {
|
||||
cmd.push_char('"');
|
||||
}
|
||||
for i in range(0u, arg.len()) {
|
||||
append_char_at(cmd, arg, i);
|
||||
let argvec: Vec<char> = arg.chars().collect();
|
||||
for i in range(0u, argvec.len()) {
|
||||
append_char_at(cmd, &argvec, i);
|
||||
}
|
||||
if quote {
|
||||
cmd.push_char('"');
|
||||
}
|
||||
}
|
||||
|
||||
fn append_char_at(cmd: &mut StrBuf, arg: &str, i: uint) {
|
||||
match arg[i] as char {
|
||||
fn append_char_at(cmd: &mut StrBuf, arg: &Vec<char>, i: uint) {
|
||||
match *arg.get(i) {
|
||||
'"' => {
|
||||
// Escape quotes.
|
||||
cmd.push_str("\\\"");
|
||||
@ -438,11 +439,11 @@ fn make_command_line(prog: &str, args: &[~str]) -> ~str {
|
||||
}
|
||||
}
|
||||
|
||||
fn backslash_run_ends_in_quote(s: &str, mut i: uint) -> bool {
|
||||
while i < s.len() && s[i] as char == '\\' {
|
||||
fn backslash_run_ends_in_quote(s: &Vec<char>, mut i: uint) -> bool {
|
||||
while i < s.len() && *s.get(i) == '\\' {
|
||||
i += 1;
|
||||
}
|
||||
return i < s.len() && s[i] as char == '"';
|
||||
return i < s.len() && *s.get(i) == '"';
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user