Signal an error in the dependency checker if an import URI is invalid (#11557)

Fixes https://github.com/flutter/flutter/issues/11539
This commit is contained in:
Jason Simmons 2017-08-09 10:08:11 -07:00 committed by GitHub
parent 859d8d3830
commit 13dda7cf80
5 changed files with 30 additions and 1 deletions

View File

@ -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') {

View File

@ -82,5 +82,19 @@ void main() {
final Set<String> 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'));
}
});
});
}

View File

@ -0,0 +1,3 @@
analyzer:
exclude:
- '**'

View File

@ -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';