From 8522ec7e1148563f645bf54cea8a2c28dcda6f26 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 1 Dec 2020 10:00:30 -0800 Subject: [PATCH] Validate empty observatory URI for screenshot (#71451) --- .../flutter_tools/lib/src/commands/screenshot.dart | 3 +++ .../general.shard/screenshot_command_test.dart | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/screenshot.dart b/packages/flutter_tools/lib/src/commands/screenshot.dart index a116e5b949e..d6370fd3555 100644 --- a/packages/flutter_tools/lib/src/commands/screenshot.dart +++ b/packages/flutter_tools/lib/src/commands/screenshot.dart @@ -77,6 +77,9 @@ class ScreenshotCommand extends FlutterCommand { if (observatoryUri == null) { throwToolExit('Observatory URI must be specified for screenshot type $screenshotType'); } + if (observatoryUri.isEmpty || Uri.tryParse(observatoryUri) == null) { + throwToolExit('Observatory URI "$observatoryUri" is invalid'); + } } } diff --git a/packages/flutter_tools/test/general.shard/screenshot_command_test.dart b/packages/flutter_tools/test/general.shard/screenshot_command_test.dart index 1eba9fbb48b..4891546593b 100644 --- a/packages/flutter_tools/test/general.shard/screenshot_command_test.dart +++ b/packages/flutter_tools/test/general.shard/screenshot_command_test.dart @@ -15,8 +15,18 @@ void main() { }); testUsingContext('rasterizer and skia screenshots require observatory uri', () async { - expect(() => ScreenshotCommand.validateOptions('rasterizer', null, null), throwsToolExit()); - expect(() => ScreenshotCommand.validateOptions('skia', null, null), throwsToolExit()); + expect( + () => ScreenshotCommand.validateOptions('rasterizer', null, null), + throwsToolExit( + message: + 'Observatory URI must be specified for screenshot type rasterizer')); + expect( + () => ScreenshotCommand.validateOptions('skia', null, null), + throwsToolExit( + message: + 'Observatory URI must be specified for screenshot type skia')); + expect(() => ScreenshotCommand.validateOptions('skia', null, ''), + throwsToolExit(message: 'Observatory URI "" is invalid')); }); testUsingContext('device screenshots require device', () async {