306f8e04bb
path may contain spaces. When it is passed into CreatProcessW, it will interpret in several ways. Escape path for CreateProcessW to remove ambiguity. Make sure [path] won't be escaped again. Bug:https://github.com/dart-lang/sdk/issues/37751 Change-Id: I70914c7c2e17aad660126662ab0e83eebe348892 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112934 Commit-Queue: Zichang Guo <zichangguo@google.com> Reviewed-by: Siva Annamalai <asiva@google.com> Reviewed-by: Zach Anderson <zra@google.com>
64 lines
2.2 KiB
Dart
64 lines
2.2 KiB
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
|
|
import "package:expect/expect.dart";
|
|
import "package:path/path.dart" as path;
|
|
|
|
import "process_test_util.dart";
|
|
|
|
void testProcessRunBinaryOutput() {
|
|
var result = Process.runSync(
|
|
getProcessTestFileName(), const ["0", "0", "0", "0"],
|
|
stdoutEncoding: null);
|
|
Expect.isTrue(result.stdout is List<int>);
|
|
Expect.isTrue(result.stderr is String);
|
|
|
|
result = Process.runSync(getProcessTestFileName(), const ["0", "0", "0", "0"],
|
|
stderrEncoding: null);
|
|
Expect.isTrue(result.stdout is String);
|
|
Expect.isTrue(result.stderr is List<int>);
|
|
|
|
result = Process.runSync(getProcessTestFileName(), const ["0", "0", "0", "0"],
|
|
stdoutEncoding: null, stderrEncoding: null);
|
|
Expect.isTrue(result.stdout is List<int>);
|
|
Expect.isTrue(result.stderr is List<int>);
|
|
}
|
|
|
|
void testProcessPathWithSpace() {
|
|
// Bug: https://github.com/dart-lang/sdk/issues/37751
|
|
var processTest = new File(getProcessTestFileName());
|
|
var dir = Directory.systemTemp.createTempSync('process_run_test');
|
|
try {
|
|
File(path.join(dir.path, 'path')).createSync();
|
|
var innerDir = Directory(path.join(dir.path, 'path with space'));
|
|
innerDir.createSync();
|
|
processTest = processTest.copySync(path.join(
|
|
innerDir.path, 'process_run_test${getPlatformExecutableExtension()}'));
|
|
// It will run executables without throwing exception.
|
|
var result = Process.runSync(processTest.path, []);
|
|
// Kill the isolate because next test reuse the exe file.
|
|
Process.killPid(result.pid);
|
|
// Manually escape the path
|
|
if (Platform.isWindows) {
|
|
result = Process.runSync('"${processTest.path}"', []);
|
|
Process.killPid(result.pid);
|
|
}
|
|
result = Process.runSync('${processTest.path}', []);
|
|
Process.killPid(result.pid);
|
|
} catch (e) {
|
|
Expect.fail('System should find process_run_test executable');
|
|
print(e);
|
|
} finally {
|
|
// Clean up the temp files and directory
|
|
dir.deleteSync(recursive: true);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
testProcessRunBinaryOutput();
|
|
testProcessPathWithSpace();
|
|
}
|