[flutter_tool] Some additional input validation for 'version' (#39136)

This commit is contained in:
Zachary Anderson 2019-08-26 12:12:50 -07:00 committed by GitHub
parent 7f5540faac
commit e9bd2ef087
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -65,6 +65,10 @@ class VersionCommand extends FlutterCommand {
// check min supported version
final Version targetVersion = Version.parse(version);
if (targetVersion == null) {
throwToolExit('Failed to parse version "$version"');
}
bool withForce = false;
if (targetVersion < minSupportedVersion) {
if (!argResults['force']) {

View file

@ -62,6 +62,16 @@ void main() {
ProcessManager: () => MockProcessManager(),
});
testUsingContext('tool exit on confusing version', () async {
const String version = 'master';
final VersionCommand command = VersionCommand();
final Future<void> runCommand = createTestCommandRunner(command).run(<String>['version', version]);
expect(() async => await Future.wait<void>(<Future<void>>[runCommand]),
throwsA(isInstanceOf<ToolExit>()));
}, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(),
});
testUsingContext('exit tool if can\'t get the tags', () async {
final VersionCommand command = VersionCommand();