Fix a crash.

We were choking on URIs without path components. This doesn't come up
frequently for file: URIs, but it's common for http: URIs.

R=rnystrom@google.com

Review URL: https://codereview.chromium.org//2268153003 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c280641..086a015 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.0.2
+
+* Don't crash on URIs without path components.
+
 ## 1.0.1
 
 * Internal changes only.
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 77de03d..e7c605c 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -77,6 +77,7 @@
 ///
 /// If [uri] already ends in a slash, returns it as-is.
 Uri ensureTrailingSlash(Uri uri) {
+  if (uri.pathSegments.isEmpty) return uri.replace(path: "/");
   if (uri.pathSegments.last.isEmpty) return uri;
   return uri.replace(pathSegments: uri.pathSegments.toList()..add(""));
 }
diff --git a/pubspec.yaml b/pubspec.yaml
index de2c1bb..05454ee 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: package_resolver
-version: 1.0.1
+version: 1.0.2
 description: First-class package resolution strategy classes.
 author: Dart Team <misc@dartlang.org>
 homepage: https://github.com/dart-lang/package_resolver
diff --git a/test/package_root_info_test.dart b/test/package_root_info_test.dart
index c0edba6..f05f20c 100644
--- a/test/package_root_info_test.dart
+++ b/test/package_root_info_test.dart
@@ -22,6 +22,12 @@
       expect(resolver.packageRoot, equals(Uri.parse("file:///foo/bar/")));
     });
 
+    test("with a URI without a path component", () {
+      var resolver =
+          new SyncPackageResolver.root(Uri.parse("http://localhost:1234"));
+      expect(resolver.packageRoot, equals(Uri.parse("http://localhost:1234/")));
+    });
+
     test("with an invalid URI type", () {
       expect(() => new SyncPackageResolver.root(12), throwsArgumentError);
     });