From b6cce7ea5497977291f4ae57937360978e764e41 Mon Sep 17 00:00:00 2001
From: Phil Ruffwind <rf@rufflewind.com>
Date: Sun, 4 May 2014 17:27:42 -0400
Subject: [PATCH] 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.
---
 src/libnative/io/process.rs | 15 ++++++++-------
 1 file 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) == '"';
     }
 }