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

Unified Diff: runtime/bin/vmservice/loader.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: Do allow package:foo.dart with a package root. Update tests to match. Created 4 years, 6 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 | tests/isolate/isolate.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/vmservice/loader.dart
diff --git a/runtime/bin/vmservice/loader.dart b/runtime/bin/vmservice/loader.dart
index 977fd28f7826d8c435c5da2846ee057adb6a4924..82fbe5e0e11ca845625b9da5b8b49515a6d473c7 100644
--- a/runtime/bin/vmservice/loader.dart
+++ b/runtime/bin/vmservice/loader.dart
@@ -116,15 +116,16 @@ class IsolateLoaderState extends IsolateEmbedderData {
_setPackageRoot(String packageRoot) {
packageRoot = _sanitizeWindowsPath(packageRoot);
- packageRoot = _enforceTrailingSlash(packageRoot);
if (packageRoot.startsWith('file:') ||
packageRoot.startsWith('http:') ||
packageRoot.startsWith('https:')) {
+ packageRoot = _enforceTrailingSlash(packageRoot);
_packageRoot = _workingDirectory.resolve(packageRoot);
} else {
packageRoot = _sanitizeWindowsPath(packageRoot);
packageRoot = _trimWindowsPath(packageRoot);
- _packageRoot = _workingDirectory.resolveUri(new Uri.file(packageRoot));
+ _packageRoot =
+ _workingDirectory.resolveUri(new Uri.directory(packageRoot));
}
}
@@ -163,12 +164,12 @@ class IsolateLoaderState extends IsolateEmbedderData {
List<Function> _pendingPackageLoads = [];
// 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';
@@ -177,6 +178,12 @@ class IsolateLoaderState extends IsolateEmbedderData {
"'$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}'";
+ }
if (_traceLoading) {
_log('Resolving package with uri path: ${uri.path}');
}
@@ -189,7 +196,13 @@ class IsolateLoaderState extends IsolateEmbedderData {
} else if (_packageRoot != null) {
resolvedUri = _packageRoot.resolve(uri.path);
} else {
- var packageName = uri.pathSegments[0];
+ 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}'";
+ }
+ var packageName = uri.path.substring(0, packageNameEnd);
var mapping = _packageMap[packageName];
if (_traceLoading) {
_log("Mapped '$packageName' package to '$mapping'");
@@ -198,14 +211,8 @@ class IsolateLoaderState extends IsolateEmbedderData {
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 | tests/isolate/isolate.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698