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

Unified Diff: runtime/bin/builtin.dart

Issue 1998603002: Make VM resolvePackageUri fail on package:foo and package:/foo. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/builtin.dart
diff --git a/runtime/bin/builtin.dart b/runtime/bin/builtin.dart
index f0c0cdcf666adcbed7c9b14d0727df9ec4c35e7a..90213e89ce9535e2e304a8d3711829bd4992bf97 100644
--- a/runtime/bin/builtin.dart
+++ b/runtime/bin/builtin.dart
@@ -268,12 +268,12 @@ _setPackageRoot(String packageRoot) {
// Given a uri with a 'package' scheme, return a Uri that is prefixed with
-// the package root.
+// the package root or resolved relative to the package configuration.
Uri _resolvePackageUri(Uri uri) {
assert(uri.scheme == "package");
assert(_packagesReady);
- if (!uri.host.isEmpty) {
+ if (uri.host.isNotEmpty) {
var path = '${uri.host}${uri.path}';
var right = 'package:$path';
var wrong = 'package://$path';
@@ -281,7 +281,18 @@ Uri _resolvePackageUri(Uri uri) {
throw "URIs using the 'package:' scheme should look like "
"'$right', not '$wrong'.";
}
-
+ var packageNameEnd = uri.path.indexOf('/');
+ if (packageNameEnd == 0) {
+ // Package URIs must have a non-empty package name (not start with "/").
+ throw "URIS using the 'package:' scheme should look like "
+ "'package:packageName${uri.path}', not 'package:${uri.path}'";
Lasse Reichstein Nielsen 2016/05/19 10:55:25 This case wasn't handled before, but with a packag
+ }
+ if (packageNameEnd < 0) {
+ // Package URIs must have a path after the package name, even if it's
+ // just "/".
+ throw "URIS using the 'package:' scheme should look like "
+ "'package:${uri.path}/', not 'package:${uri.path}'";
+ }
if (_traceLoading) {
_log('Resolving package with uri path: ${uri.path}');
}
@@ -294,7 +305,7 @@ Uri _resolvePackageUri(Uri uri) {
} else if (_packageRoot != null) {
resolvedUri = _packageRoot.resolve(uri.path);
} else {
- var packageName = uri.pathSegments[0];
+ var packageName = uri.path.substring(0, packageNameEnd);
var mapping = _packageMap[packageName];
if (_traceLoading) {
_log("Mapped '$packageName' package to '$mapping'");
@@ -303,14 +314,8 @@ Uri _resolvePackageUri(Uri uri) {
throw "No mapping for '$packageName' package when resolving '$uri'.";
}
var path;
- if (uri.path.length > packageName.length) {
- path = uri.path.substring(packageName.length + 1);
- } else {
- // Handle naked package resolution to the default package name:
- // package:foo is equivalent to package:foo/foo.dart
- assert(uri.path.length == packageName.length);
- path = "$packageName.dart";
- }
+ assert(uri.path.length > packageName.length);
+ path = uri.path.substring(packageName.length + 1);
if (_traceLoading) {
_log("Path to be resolved in package: $path");
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698