fix list devices throwing on junk input (#27615)
This commit is contained in:
@@ -115,7 +115,7 @@ class FuchsiaDevices extends PollingDeviceDiscovery {
|
||||
return <Device>[];
|
||||
}
|
||||
final String text = await fuchsiaSdk.listDevices();
|
||||
if (text == null) {
|
||||
if (text == null || text.isEmpty) {
|
||||
return <Device>[];
|
||||
}
|
||||
final List<FuchsiaDevice> devices = parseListDevices(text);
|
||||
@@ -133,6 +133,9 @@ List<FuchsiaDevice> parseListDevices(String text) {
|
||||
final String line = rawLine.trim();
|
||||
// ['ip', 'device name']
|
||||
final List<String> words = line.split(' ');
|
||||
if (words.length < 2) {
|
||||
continue;
|
||||
}
|
||||
final String name = words[1];
|
||||
final String id = words[0];
|
||||
devices.add(FuchsiaDevice(id, name: name));
|
||||
|
||||
@@ -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<FuchsiaDevice> names = parseListDevices(example);
|
||||
|
||||
expect(names.length, 0);
|
||||
});
|
||||
|
||||
test('default capabilities', () async {
|
||||
final FuchsiaDevice device = FuchsiaDevice('123');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user