diff options
| author | Phil Ruffwind <rf@rufflewind.com> | 2014-05-04 17:27:42 -0400 |
|---|---|---|
| committer | Phil Ruffwind <rf@rufflewind.com> | 2014-05-13 17:19:00 -0400 |
| commit | b6cce7ea5497977291f4ae57937360978e764e41 (patch) | |
| tree | abab69acc49459e6a354cc577831b0a1d46dbf36 /src/libnative | |
| parent | e12aeb39bc4221421890011006c5ae23154cc695 (diff) | |
| download | rust-b6cce7ea5497977291f4ae57937360978e764e41.tar.gz rust-b6cce7ea5497977291f4ae57937360978e764e41.zip | |
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.
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/process.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index dbb191911e7..be67d0a3fb4 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -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) == '"'; } } |
