Skip to content

Commit b6cce7e

Browse files
committed
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.
1 parent e12aeb3 commit b6cce7e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/libnative/io/process.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,17 @@ fn make_command_line(prog: &str, args: &[~str]) -> ~str {
409409
if quote {
410410
cmd.push_char('"');
411411
}
412-
for i in range(0u, arg.len()) {
413-
append_char_at(cmd, arg, i);
412+
let argvec: Vec<char> = arg.chars().collect();
413+
for i in range(0u, argvec.len()) {
414+
append_char_at(cmd, &argvec, i);
414415
}
415416
if quote {
416417
cmd.push_char('"');
417418
}
418419
}
419420

420-
fn append_char_at(cmd: &mut StrBuf, arg: &str, i: uint) {
421-
match arg[i] as char {
421+
fn append_char_at(cmd: &mut StrBuf, arg: &Vec<char>, i: uint) {
422+
match *arg.get(i) {
422423
'"' => {
423424
// Escape quotes.
424425
cmd.push_str("\\\"");
@@ -438,11 +439,11 @@ fn make_command_line(prog: &str, args: &[~str]) -> ~str {
438439
}
439440
}
440441

441-
fn backslash_run_ends_in_quote(s: &str, mut i: uint) -> bool {
442-
while i < s.len() && s[i] as char == '\\' {
442+
fn backslash_run_ends_in_quote(s: &Vec<char>, mut i: uint) -> bool {
443+
while i < s.len() && *s.get(i) == '\\' {
443444
i += 1;
444445
}
445-
return i < s.len() && s[i] as char == '"';
446+
return i < s.len() && *s.get(i) == '"';
446447
}
447448
}
448449

0 commit comments

Comments
 (0)