Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1163)

Unified Diff: pkg/front_end/lib/src/fasta/translate_uri.dart

Issue 2804843003: Fix some crashes. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/lib/src/fasta/source/source_loader.dart ('k') | tests/corelib/corelib.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/translate_uri.dart
diff --git a/pkg/front_end/lib/src/fasta/translate_uri.dart b/pkg/front_end/lib/src/fasta/translate_uri.dart
index 429a65730bc11d336800761c5dadcf4f1fce79d7..37d98eeb3ca6998dac354f03a84c42f346f82848 100644
--- a/pkg/front_end/lib/src/fasta/translate_uri.dart
+++ b/pkg/front_end/lib/src/fasta/translate_uri.dart
@@ -6,10 +6,14 @@ library fasta.translate_uri;
import 'dart:async' show Future;
-import 'dart:io' show File;
-
import 'package:package_config/packages_file.dart' as packages_file show parse;
+import 'errors.dart' show inputError;
+
+import 'io.dart' show readBytesFromFile;
+
+import 'scanner/characters.dart' show $LF;
+
class TranslateUri {
final Map<String, Uri> packages;
final Map<String, Uri> dartLibraries;
@@ -74,9 +78,16 @@ class TranslateUri {
};
}
uri ??= Uri.base.resolve(".packages");
- File file = new File.fromUri(uri);
- List<int> bytes = await file.readAsBytes();
- Map<String, Uri> packages = packages_file.parse(bytes, uri);
+ List<int> bytes = await readBytesFromFile(uri);
+ Map<String, Uri> packages = const <String, Uri>{};
+ try {
+ // We always add an extra zero byte at the end of files. We change that
+ // to a newline to avoid a format error from `packages_file.parse`.
+ bytes[bytes.length - 1] = $LF;
+ packages = packages_file.parse(bytes, uri);
+ } on FormatException catch (e) {
+ return inputError(uri, e.offset, e.message);
+ }
return new TranslateUri(packages, dartLibraries);
}
}
« no previous file with comments | « pkg/front_end/lib/src/fasta/source/source_loader.dart ('k') | tests/corelib/corelib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698