From 5b943257d7b65012ffb3062ec2c2ff9e55c78d06 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 6 Feb 2019 15:41:22 -0800 Subject: [PATCH] fix list devices throwing on junk input (#27615) --- packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart | 5 ++++- .../flutter_tools/test/fuchsia/fuchsa_device_test.dart | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart index 844bdbfdaf..e874d6b061 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart @@ -115,7 +115,7 @@ class FuchsiaDevices extends PollingDeviceDiscovery { return []; } final String text = await fuchsiaSdk.listDevices(); - if (text == null) { + if (text == null || text.isEmpty) { return []; } final List devices = parseListDevices(text); @@ -133,6 +133,9 @@ List parseListDevices(String text) { final String line = rawLine.trim(); // ['ip', 'device name'] final List words = line.split(' '); + if (words.length < 2) { + continue; + } final String name = words[1]; final String id = words[0]; devices.add(FuchsiaDevice(id, name: name)); diff --git a/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart b/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart index 87ab363118..452fde7c1e 100644 --- a/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart +++ b/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart @@ -40,6 +40,13 @@ void main() { expect(names.first.id, '192.168.42.56'); }); + test('parse junk dev_finder output', () { + const String example = 'junk'; + final List names = parseListDevices(example); + + expect(names.length, 0); + }); + test('default capabilities', () async { final FuchsiaDevice device = FuchsiaDevice('123');