Chromium Code Reviews| Index: runtime/bin/process_impl.dart |
| diff --git a/runtime/bin/process_impl.dart b/runtime/bin/process_impl.dart |
| index 2fcdaabfc2ee5e64eb688fccdb64edf1c459a5f0..d3d17d9e801ad8abb295d287b9c6f29a559eddf9 100644 |
| --- a/runtime/bin/process_impl.dart |
| +++ b/runtime/bin/process_impl.dart |
| @@ -29,6 +29,9 @@ class _Process implements Process { |
| throw new ProcessException("Non-string argument: $arg"); |
| } |
| _arguments[i] = arguments[i]; |
| + if (new Platform().operatingSystem() == 'windows') { |
| + _arguments[i] = _windowsArgumentEscape(_arguments[i]); |
| + } |
| } |
| if (workingDirectory is !String && workingDirectory !== null) { |
| @@ -50,6 +53,51 @@ class _Process implements Process { |
| new Timer(0, (Timer ignore) => start()); |
| } |
| + String _windowsArgumentEscape(String argument) { |
| + var result = argument; |
| + if (argument.contains('\t') || argument.contains(' ')) { |
| + // Produce something that the C runtime on Windows will parse |
| + // back as this string. |
| + |
| + // Replace any number of '\' followed by '"' with |
| + // twice as many '\' followed by '\"'. |
|
Anton Muhin
2012/03/15 14:59:39
I don't know the current status of RegExps, but it
Mads Ager (google)
2012/03/15 15:32:02
Yeah, it does. I don't believe that there is suppo
|
| + StringBuffer sb = new StringBuffer(); |
| + var nextPos = 0; |
| + var quotePos = argument.indexOf('"', nextPos); |
| + while (quotePos != -1) { |
|
Anton Muhin
2012/03/15 14:59:39
absolutely up to you, but I would structure the l
Mads Ager (google)
2012/03/15 15:32:02
I don't really like any of them. I like the explic
|
| + var numBackslash = 0; |
| + var pos = quotePos - 1; |
| + while (pos >= 0 && argument.charCodeAt(pos) == '\\'.charCodeAt(0)) { |
| + numBackslash++; |
| + pos--; |
| + } |
| + sb.add(argument.substring(nextPos, quotePos - numBackslash)); |
| + for (var i = 0; i < numBackslash; i++) { |
| + sb.add(@'\\'); |
| + } |
| + sb.add(@'\"'); |
| + nextPos = quotePos + 1; |
| + quotePos = argument.indexOf('"', nextPos); |
| + } |
| + sb.add(argument.substring(nextPos, argument.length)); |
| + result = sb.toString(); |
| + |
| + // Add '"' at the beginning and end and replace all '\' at |
| + // the end with two '\'. |
| + sb = new StringBuffer('"'); |
| + sb.add(result); |
| + nextPos = argument.length - 1; |
| + while (argument.charCodeAt(nextPos) == '\\'.charCodeAt(0)) { |
| + sb.add('\\'); |
| + nextPos--; |
| + } |
| + sb.add('"'); |
| + result = sb.toString(); |
| + } |
| + |
| + return result; |
| + } |
| + |
| int _intFromBytes(List<int> bytes, int offset) { |
| return (bytes[offset] + |
| (bytes[offset + 1] << 8) + |