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"); |
} |