Skip to content

Commit

Permalink
Fix make_command_line to handle Unicode correctly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Rufflewind committed May 13, 2014
1 parent e12aeb3 commit b6cce7e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/libnative/io/process.rs
Expand Up @@ -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("\\\"");
Expand All @@ -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) == '"';
}
}

Expand Down

0 comments on commit b6cce7e

Please sign in to comment.