Fix for resolving file URIs with special characters in BazelPackageUriResolver.

Change-Id: I2e9bb40aa3460b3b60e2354bff1b456851815ce9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179720
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/workspace/bazel.dart b/pkg/analyzer/lib/src/workspace/bazel.dart
index bb6aaed..db269c0 100644
--- a/pkg/analyzer/lib/src/workspace/bazel.dart
+++ b/pkg/analyzer/lib/src/workspace/bazel.dart
@@ -232,7 +232,8 @@
   Source resolveAbsolute(Uri uri, [Uri actualUri]) {
     return _sourceCache.putIfAbsent(uri, () {
       if (uri.scheme == 'file') {
-        var pathRelativeToRoot = _workspace._relativeToRoot(uri.path);
+        var path = fileUriToNormalizedPath(_context, uri);
+        var pathRelativeToRoot = _workspace._relativeToRoot(path);
         if (pathRelativeToRoot == null) return null;
         var fullFilePath = _context.join(_workspace.root, pathRelativeToRoot);
         File file = _workspace.findFile(fullFilePath);
diff --git a/pkg/analyzer/test/src/workspace/bazel_test.dart b/pkg/analyzer/test/src/workspace/bazel_test.dart
index f64cfc9..9d7cd6e 100644
--- a/pkg/analyzer/test/src/workspace/bazel_test.dart
+++ b/pkg/analyzer/test/src/workspace/bazel_test.dart
@@ -134,6 +134,16 @@
         exists: true);
   }
 
+  void test_resolveAbsolute_file_bin_pathHasSpace() {
+    _addResources([
+      '/workspace/WORKSPACE',
+      '/workspace/my/foo/test',
+    ]);
+    _assertResolve('file:///workspace/bazel-bin/my/test/a .dart',
+        '/workspace/my/test/a .dart',
+        exists: false, restore: false);
+  }
+
   void test_resolveAbsolute_file_bin_to_genfiles() {
     _addResources([
       '/workspace/WORKSPACE',