diff --git a/packages/flutter_tools/lib/src/fuchsia/amber_ctl.dart b/packages/flutter_tools/lib/src/fuchsia/amber_ctl.dart index d1b4c978bb..3c806fb48c 100644 --- a/packages/flutter_tools/lib/src/fuchsia/amber_ctl.dart +++ b/packages/flutter_tools/lib/src/fuchsia/amber_ctl.dart @@ -58,7 +58,7 @@ class FuchsiaAmberCtl { /// Teaches the amber instance running on [device] about the Fuchsia package /// server accessible via [configUrl]. Future addSrc(FuchsiaDevice device, FuchsiaPackageServer server) async { - final String configUrl = '${server.url}/config.json'; + final String configUrl = '${server.interfaceStrippedUrl}/config.json'; final RunResult result = await device.shell('amber_ctl add_src -x -f $configUrl'); return result.exitCode == 0; @@ -68,7 +68,7 @@ class FuchsiaAmberCtl { /// Fuchsia package server that it was accessing via [serverUrl]. Future rmSrc(FuchsiaDevice device, FuchsiaPackageServer server) async { final RunResult result = - await device.shell('amber_ctl rm_src -n ${server.url}'); + await device.shell('amber_ctl rm_src -n ${server.interfaceStrippedUrl}'); return result.exitCode == 0; } @@ -84,7 +84,7 @@ class FuchsiaAmberCtl { /// pkg_resolver repo config, and teaches the pkg_resolver instance running /// on [device] about the [FuchsiaPackageServer]. Future addRepoCfg(FuchsiaDevice device, FuchsiaPackageServer server) async { - final String configUrl = '${server.url}/config.json'; + final String configUrl = '${server.interfaceStrippedUrl}/config.json'; final RunResult result = await device.shell('amber_ctl add_repo_cfg -n ${server.name} -f $configUrl'); return result.exitCode == 0; diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart index ed791bd8f6..7ed70e2119 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart @@ -111,7 +111,7 @@ class FuchsiaPM { throwToolExit('Fuchsia pm tool not found'); } if (isIPv6Address(host.split('%').first)) { - host = '[${host.replaceAll('%', '%25')}]'; + host = '[$host]'; } final List command = [ globals.fuchsiaArtifacts.pm.path, @@ -181,12 +181,6 @@ class FuchsiaPM { /// } class FuchsiaPackageServer { factory FuchsiaPackageServer(String repo, String name, String host, int port) { - // TODO(jonahwilliams): ensure we only receive valid ipv4 or ipv6 InternetAddresses. - // Temporary work around to receiving ipv6 addresses with trailing information: - // fe80::ec4:7aff:fecc:ea8f%eno2 - if (host.contains('%')) { - host = host.split('%').first; - } return FuchsiaPackageServer._(repo, name, host, port); } @@ -204,6 +198,14 @@ class FuchsiaPackageServer { /// The URL that can be used by the device to access this package server. String get url => Uri(scheme: 'http', host: _host, port: _port).toString(); + /// The URL that is stripped of interface name if it is an ipv6 address, + /// which should be supplied to amber_ctl to configure access to host + String get interfaceStrippedUrl => Uri( + scheme: 'http', + host: (isIPv6Address(_host.split('%').first)) ? '[${_host.split('%').first}]' : _host, + port: _port, + ).toString(); + // The name used to reference the server by fuchsia-pkg:// urls. final String name; diff --git a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_pm_test.dart b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_pm_test.dart index f95be6e19c..fb0315860d 100644 --- a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_pm_test.dart +++ b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_pm_test.dart @@ -65,7 +65,7 @@ void main() { '-repo', '', '-l', - '[fe80::ec4:7aff:fecc:ea8f%25eno2]:43819', + '[fe80::ec4:7aff:fecc:ea8f%eno2]:43819', ])).called(1); }, overrides: { FuchsiaArtifacts: () => mockFuchsiaArtifacts, @@ -78,6 +78,11 @@ void main() { expect( FuchsiaPackageServer('a', 'b', host, port).url, + 'http://[fe80::ec4:7aff:fecc:ea8f%25eno2]:23', + ); + + expect( + FuchsiaPackageServer('a', 'b', host, port).interfaceStrippedUrl, 'http://[fe80::ec4:7aff:fecc:ea8f]:23', ); });