Skip to content

Commit 8c02b8f

Browse files
matteocrippatvolkert
authored andcommitted
Fix issue for iOS to build any app and run on simulator flutter#19618 (flutter#19863)
A different approach to get the url from the string and avoid any interference by extra chars not allowed in url Fixes flutter#19618
1 parent a0b5448 commit 8c02b8f

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

packages/flutter_tools/lib/src/protocol_discovery.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class ProtocolDiscovery {
1717
this.portForwarder,
1818
this.hostPort,
1919
this.ipv6,
20-
}) : assert(logReader != null),
21-
_prefix = '$serviceName listening on ' {
20+
}) : assert(logReader != null) {
2221
_deviceLogSubscription = logReader.logLines.listen(_handleLine);
2322
}
2423

@@ -30,7 +29,8 @@ class ProtocolDiscovery {
3029
}) {
3130
const String kObservatoryService = 'Observatory';
3231
return new ProtocolDiscovery._(
33-
logReader, kObservatoryService,
32+
logReader,
33+
kObservatoryService,
3434
portForwarder: portForwarder,
3535
hostPort: hostPort,
3636
ipv6: ipv6,
@@ -43,7 +43,6 @@ class ProtocolDiscovery {
4343
final int hostPort;
4444
final bool ipv6;
4545

46-
final String _prefix;
4746
final Completer<Uri> _completer = new Completer<Uri>();
4847

4948
StreamSubscription<String> _deviceLogSubscription;
@@ -60,10 +59,13 @@ class ProtocolDiscovery {
6059

6160
void _handleLine(String line) {
6261
Uri uri;
63-
final int index = line.indexOf(_prefix + 'http://');
64-
if (index >= 0) {
62+
63+
final RegExp r = new RegExp('${RegExp.escape(serviceName)} listening on (http://[^ \n]+)');
64+
final Match match = r.firstMatch(line);
65+
66+
if (match != null) {
6567
try {
66-
uri = Uri.parse(line.substring(index + _prefix.length));
68+
uri = Uri.parse(match[1]);
6769
} catch (error) {
6870
_stopScrapingLogs();
6971
_completer.completeError(error);
@@ -75,6 +77,7 @@ class ProtocolDiscovery {
7577
_stopScrapingLogs();
7678
_completer.complete(_forwardPort(uri));
7779
}
80+
7881
}
7982

8083
Future<Uri> _forwardPort(Uri deviceUri) async {

packages/flutter_tools/test/protocol_discovery_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ void main() {
6666
expect('$uri', 'http://127.0.0.1:3333');
6767
});
6868

69+
testUsingContext('discovers uri even if logs has ESC Ascii', () async {
70+
initialize();
71+
logReader.addLine('Observatory listening on http://127.0.0.1:3333 \x1b[');
72+
final Uri uri = await discoverer.uri;
73+
expect(uri.port, 3333);
74+
expect('$uri', 'http://127.0.0.1:3333');
75+
});
76+
6977
testUsingContext('uri throws if logs produce bad line', () async {
7078
initialize();
7179
Timer.run(() {

0 commit comments

Comments
 (0)