mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
A different approach to get the url from the string and avoid any interference by extra chars not allowed in url Fixes #19618
This commit is contained in:
parent
a0b5448b84
commit
8c02b8f889
@ -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(() {
|
||||
|
Loading…
Reference in New Issue
Block a user