Commit 8c02b8f8 authored by Matteo Crippa's avatar Matteo Crippa Committed by Todd Volkert

Fix issue for iOS to build any app and run on simulator #19618 (#19863)

A different approach to get the url from the string and avoid any interference by extra chars not allowed in url

Fixes #19618
parent a0b5448b
......@@ -17,8 +17,7 @@ class ProtocolDiscovery {
this.portForwarder,
this.hostPort,
this.ipv6,
}) : assert(logReader != null),
_prefix = '$serviceName listening on ' {
}) : assert(logReader != null) {
_deviceLogSubscription = logReader.logLines.listen(_handleLine);
}
......@@ -30,7 +29,8 @@ class ProtocolDiscovery {
}) {
const String kObservatoryService = 'Observatory';
return new ProtocolDiscovery._(
logReader, kObservatoryService,
logReader,
kObservatoryService,
portForwarder: portForwarder,
hostPort: hostPort,
ipv6: ipv6,
......@@ -43,7 +43,6 @@ class ProtocolDiscovery {
final int hostPort;
final bool ipv6;
final String _prefix;
final Completer<Uri> _completer = new Completer<Uri>();
StreamSubscription<String> _deviceLogSubscription;
......@@ -60,10 +59,13 @@ class ProtocolDiscovery {
void _handleLine(String line) {
Uri uri;
final int index = line.indexOf(_prefix + 'http://');
if (index >= 0) {
final RegExp r = new RegExp('${RegExp.escape(serviceName)} listening on (http://[^ \n]+)');
final Match match = r.firstMatch(line);
if (match != null) {
try {
uri = Uri.parse(line.substring(index + _prefix.length));
uri = Uri.parse(match[1]);
} catch (error) {
_stopScrapingLogs();
_completer.completeError(error);
......@@ -75,6 +77,7 @@ class ProtocolDiscovery {
_stopScrapingLogs();
_completer.complete(_forwardPort(uri));
}
}
Future<Uri> _forwardPort(Uri deviceUri) async {
......
......@@ -66,6 +66,14 @@ void main() {
expect('$uri', 'http://127.0.0.1:3333');
});
testUsingContext('discovers uri even if logs has ESC Ascii', () async {
initialize();
logReader.addLine('Observatory listening on http://127.0.0.1:3333 \x1b[');
final Uri uri = await discoverer.uri;
expect(uri.port, 3333);
expect('$uri', 'http://127.0.0.1:3333');
});
testUsingContext('uri throws if logs produce bad line', () async {
initialize();
Timer.run(() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment