Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: runtime/bin/process_impl.dart

Issue 9701061: Change quoting in Process implementation on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/process_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class _ProcessStartStatus { 5 class _ProcessStartStatus {
6 int _errorCode; // Set to OS error code if process start failed. 6 int _errorCode; // Set to OS error code if process start failed.
7 String _errorMessage; // Set to OS error message if process start failed. 7 String _errorMessage; // Set to OS error message if process start failed.
8 } 8 }
9 9
10 10
(...skipping 11 matching lines...) Expand all
22 throw new ProcessException("Arguments is not a List: $arguments"); 22 throw new ProcessException("Arguments is not a List: $arguments");
23 } 23 }
24 int len = arguments.length; 24 int len = arguments.length;
25 _arguments = new ObjectArray<String>(len); 25 _arguments = new ObjectArray<String>(len);
26 for (int i = 0; i < len; i++) { 26 for (int i = 0; i < len; i++) {
27 var arg = arguments[i]; 27 var arg = arguments[i];
28 if (arg is !String) { 28 if (arg is !String) {
29 throw new ProcessException("Non-string argument: $arg"); 29 throw new ProcessException("Non-string argument: $arg");
30 } 30 }
31 _arguments[i] = arguments[i]; 31 _arguments[i] = arguments[i];
32 if (new Platform().operatingSystem() == 'windows') {
33 _arguments[i] = _windowsArgumentEscape(_arguments[i]);
34 }
32 } 35 }
33 36
34 if (workingDirectory is !String && workingDirectory !== null) { 37 if (workingDirectory is !String && workingDirectory !== null) {
35 throw new ProcessException( 38 throw new ProcessException(
36 "WorkingDirectory is not a String: $workingDirectory"); 39 "WorkingDirectory is not a String: $workingDirectory");
37 } 40 }
38 _workingDirectory = workingDirectory; 41 _workingDirectory = workingDirectory;
39 42
40 _in = new _Socket._internalReadOnly(); // stdout coming from process. 43 _in = new _Socket._internalReadOnly(); // stdout coming from process.
41 _out = new _Socket._internalWriteOnly(); // stdin going to process. 44 _out = new _Socket._internalWriteOnly(); // stdin going to process.
42 _err = new _Socket._internalReadOnly(); // stderr coming from process. 45 _err = new _Socket._internalReadOnly(); // stderr coming from process.
43 _exitHandler = new _Socket._internalReadOnly(); 46 _exitHandler = new _Socket._internalReadOnly();
44 _closed = false; 47 _closed = false;
45 _killed = false; 48 _killed = false;
46 _started = false; 49 _started = false;
47 _onExit = null; 50 _onExit = null;
48 // TODO(ager): Make the actual process starting really async instead of 51 // TODO(ager): Make the actual process starting really async instead of
49 // simulating it with a timer. 52 // simulating it with a timer.
50 new Timer(0, (Timer ignore) => start()); 53 new Timer(0, (Timer ignore) => start());
51 } 54 }
52 55
56 String _windowsArgumentEscape(String argument) {
57 var result = argument;
58 if (argument.contains('\t') || argument.contains(' ')) {
59 // Produce something that the C runtime on Windows will parse
60 // back as this string.
61
62 // Replace any number of '\' followed by '"' with
63 // 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
64 StringBuffer sb = new StringBuffer();
65 var nextPos = 0;
66 var quotePos = argument.indexOf('"', nextPos);
67 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
68 var numBackslash = 0;
69 var pos = quotePos - 1;
70 while (pos >= 0 && argument.charCodeAt(pos) == '\\'.charCodeAt(0)) {
71 numBackslash++;
72 pos--;
73 }
74 sb.add(argument.substring(nextPos, quotePos - numBackslash));
75 for (var i = 0; i < numBackslash; i++) {
76 sb.add(@'\\');
77 }
78 sb.add(@'\"');
79 nextPos = quotePos + 1;
80 quotePos = argument.indexOf('"', nextPos);
81 }
82 sb.add(argument.substring(nextPos, argument.length));
83 result = sb.toString();
84
85 // Add '"' at the beginning and end and replace all '\' at
86 // the end with two '\'.
87 sb = new StringBuffer('"');
88 sb.add(result);
89 nextPos = argument.length - 1;
90 while (argument.charCodeAt(nextPos) == '\\'.charCodeAt(0)) {
91 sb.add('\\');
92 nextPos--;
93 }
94 sb.add('"');
95 result = sb.toString();
96 }
97
98 return result;
99 }
100
53 int _intFromBytes(List<int> bytes, int offset) { 101 int _intFromBytes(List<int> bytes, int offset) {
54 return (bytes[offset] + 102 return (bytes[offset] +
55 (bytes[offset + 1] << 8) + 103 (bytes[offset + 1] << 8) +
56 (bytes[offset + 2] << 16) + 104 (bytes[offset + 2] << 16) +
57 (bytes[offset + 3] << 24)); 105 (bytes[offset + 3] << 24));
58 } 106 }
59 107
60 void start() { 108 void start() {
61 var status = new _ProcessStartStatus(); 109 var status = new _ProcessStartStatus();
62 bool success = _start(_path, 110 bool success = _start(_path,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 Socket _err; 250 Socket _err;
203 Socket _exitHandler; 251 Socket _exitHandler;
204 int _pid; 252 int _pid;
205 bool _closed; 253 bool _closed;
206 bool _killed; 254 bool _killed;
207 bool _started; 255 bool _started;
208 Function _onExit; 256 Function _onExit;
209 Function _onError; 257 Function _onError;
210 Function _onStart; 258 Function _onStart;
211 } 259 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698