-
Notifications
You must be signed in to change notification settings - Fork 133
[hooks_runner] Fix handling of executable paths and arguments containing spaces on Windows #3466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b3f3692
Fix handling of executable paths and arguments containing spaces on W…
jakobkordez 11f9f05
Reformat run_process.dart
jakobkordez 971e68f
Update temp directory naming to handle spaces
jakobkordez fd3997a
Add support for disabling spaces in paths in temp directory functions
jakobkordez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Copyright (c) 2023, 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. | ||
|
|
||
| // Regression test for running commands whose executable path or arguments | ||
| // contain a space (e.g. the default pub cache under a Windows user name with | ||
| // a space, `C:\Users\First Last\AppData\Local\Pub\Cache\...`). | ||
| // | ||
| // On Windows, `runProcess` runs through `cmd.exe` (`runInShell`) whenever a | ||
| // `workingDirectory` is passed. `cmd.exe`'s `/c` quote-stripping rule mangles | ||
| // the command line as soon as more than one token needs quoting because it | ||
| // contains a space (the executable path and an argument, or two arguments), | ||
| // causing errors like | ||
| // `'C:\Program' is not recognized as an internal or external command`. | ||
|
|
||
| import 'dart:io'; | ||
|
|
||
| import 'package:test/test.dart'; | ||
|
|
||
| import '../helpers.dart'; | ||
|
|
||
| void main() { | ||
| late Uri scriptUri; | ||
|
|
||
| setUpAll(() async { | ||
| final scriptDir = await tempDirForTest(); | ||
| scriptUri = scriptDir.resolve('echo_args.dart'); | ||
| await File.fromUri(scriptUri).writeAsString(''' | ||
| void main(List<String> args) { | ||
| print('ARGC:\${args.length}'); | ||
| print('ARGV:\${args.join('|')}'); | ||
| } | ||
| '''); | ||
| }); | ||
|
|
||
| test( | ||
| 'runProcess handles an executable path containing a space', | ||
| timeout: const Timeout.factor(5), | ||
| () async { | ||
| final outDir = await tempDirForTest(); | ||
| final exeUri = outDir.resolve( | ||
| 'echo args${Platform.isWindows ? '.exe' : ''}', | ||
| ); | ||
| final compileResult = await Process.run(Platform.resolvedExecutable, [ | ||
| 'compile', | ||
| 'exe', | ||
| scriptUri.toFilePath(), | ||
| '-o', | ||
| exeUri.toFilePath(), | ||
| ]); | ||
| expect(compileResult.exitCode, 0, reason: '${compileResult.stderr}'); | ||
|
|
||
| final workingDir = await tempDirForTest(); | ||
| final result = await runProcess( | ||
| executable: exeUri, | ||
| arguments: ['an argument with spaces'], | ||
| workingDirectory: workingDir, | ||
| logger: logger, | ||
| ); | ||
|
|
||
| expect(result.exitCode, 0); | ||
| expect(result.stdout, contains('ARGC:1')); | ||
| expect(result.stdout, contains('ARGV:an argument with spaces')); | ||
| }, | ||
| ); | ||
|
|
||
| test('runProcess handles arguments containing a space', () async { | ||
| final workingDir = await tempDirForTest(); | ||
| final result = await runProcess( | ||
| executable: Uri.file(Platform.resolvedExecutable), | ||
| arguments: [scriptUri.toFilePath(), 'first arg', 'second arg'], | ||
| workingDirectory: workingDir, | ||
| logger: logger, | ||
| ); | ||
|
|
||
| expect(result.exitCode, 0); | ||
| expect(result.stdout, contains('ARGC:2')); | ||
| expect(result.stdout, contains('ARGV:first arg|second arg')); | ||
| }); | ||
|
|
||
| test('runProcess handles arguments containing a space and quotes', () async { | ||
| final workingDir = await tempDirForTest(); | ||
| final result = await runProcess( | ||
| executable: Uri.file(Platform.resolvedExecutable), | ||
| arguments: [scriptUri.toFilePath(), 'fir"st arg', 'sec\'ond arg'], | ||
| workingDirectory: workingDir, | ||
| logger: logger, | ||
| ); | ||
|
|
||
| expect(result.exitCode, 0); | ||
| expect(result.stdout, contains('ARGC:2')); | ||
| expect(result.stdout, contains('ARGV:fir"st arg|sec\'ond arg')); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.