diff --git a/packages/flutter_tools/lib/src/dart/dependencies.dart b/packages/flutter_tools/lib/src/dart/dependencies.dart index b116a4bbe20..28c74710fc6 100644 --- a/packages/flutter_tools/lib/src/dart/dependencies.dart +++ b/packages/flutter_tools/lib/src/dart/dependencies.dart @@ -65,7 +65,13 @@ class DartDependencySetBuilder { uriAsString = uriBasedDirective.uri.stringValue; } - Uri resolvedUri = analyzer.resolveRelativeUri(currentUri, Uri.parse(uriAsString)); + Uri uri; + try { + uri = Uri.parse(uriAsString); + } on FormatException { + throw new DartDependencyException('Unable to parse URI: $uriAsString'); + } + Uri resolvedUri = analyzer.resolveRelativeUri(currentUri, uri); if (resolvedUri.scheme.startsWith('dart')) continue; if (resolvedUri.scheme == 'package') { diff --git a/packages/flutter_tools/test/dart_dependencies_test.dart b/packages/flutter_tools/test/dart_dependencies_test.dart index edee1331e6b..81fbdb8516a 100644 --- a/packages/flutter_tools/test/dart_dependencies_test.dart +++ b/packages/flutter_tools/test/dart_dependencies_test.dart @@ -82,5 +82,19 @@ void main() { final Set deps = builder.build(); expect(deps, contains(endsWith('This_Import_Has_fuNNy_casING.dart'))); }); + + testUsingContext('bad_import', () { + final String testPath = fs.path.join(dataPath, 'bad_import'); + final String mainPath = fs.path.join(testPath, 'main.dart'); + final String packagesPath = fs.path.join(testPath, '.packages'); + final DartDependencySetBuilder builder = + new DartDependencySetBuilder(mainPath, packagesPath); + try { + builder.build(); + fail('expect an exception to be thrown.'); + } on DartDependencyException catch (error) { + expect(error.toString(), contains('Unable to parse URI')); + } + }); }); } diff --git a/packages/flutter_tools/test/data/dart_dependencies_test/bad_import/.analysis_options b/packages/flutter_tools/test/data/dart_dependencies_test/bad_import/.analysis_options new file mode 100644 index 00000000000..4c1615ac5ac --- /dev/null +++ b/packages/flutter_tools/test/data/dart_dependencies_test/bad_import/.analysis_options @@ -0,0 +1,3 @@ +analyzer: + exclude: + - '**' diff --git a/packages/flutter_tools/test/data/dart_dependencies_test/bad_import/main.dart b/packages/flutter_tools/test/data/dart_dependencies_test/bad_import/main.dart new file mode 100644 index 00000000000..c886ae45163 --- /dev/null +++ b/packages/flutter_tools/test/data/dart_dependencies_test/bad_import/main.dart @@ -0,0 +1,5 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '[object Object].dart'; diff --git a/packages/flutter_tools/test/data/dart_dependencies_test/bad_import/pubspec.yaml b/packages/flutter_tools/test/data/dart_dependencies_test/bad_import/pubspec.yaml new file mode 100644 index 00000000000..99a0109ab60 --- /dev/null +++ b/packages/flutter_tools/test/data/dart_dependencies_test/bad_import/pubspec.yaml @@ -0,0 +1 @@ +name: self