Revert "Add special character encoding and decoding to conversions"

This reverts commit a89353f5ce29acc456da221213b06d74cfd8d436.

Reason for revert: speculative revert due to roll failures https://chromium-review.googlesource.com/c/chromium/src/+/3398829

Original change's description:
> Add special character encoding and decoding to conversions
> between RawPathString and UrlString
>
> Bug: 1253323
> Change-Id: I6a774eb7129189a8c71b42c18d0a4d28e01d62e3
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3344913
> Reviewed-by: Simon Zünd <szuend@chromium.org>
> Commit-Queue: Kateryna Prokopenko <kprokopenko@chromium.org>

Bug: 1253323
Change-Id: I4781755fc6d757277c5f6de4ef3998ca5cd13724
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3398899
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
Owners-Override: Alex Rudenko <alexrudenko@chromium.org>
Reviewed-by: Nancy Li <nancyly@chromium.org>
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
diff --git a/front_end/core/common/ParsedURL.ts b/front_end/core/common/ParsedURL.ts
index ca6882b..e1f8cab 100644
--- a/front_end/core/common/ParsedURL.ts
+++ b/front_end/core/common/ParsedURL.ts
@@ -168,17 +168,16 @@
   }
 
   static rawPathToUrlString(fileSystemPath: Platform.DevToolsPath.RawPathString): Platform.DevToolsPath.UrlString {
-    let preEncodedPath: string = ParsedURL.preEncodeSpecialCharactersInPath(
-        fileSystemPath.replace(/\\/g, '/') as Platform.DevToolsPath.RawPathString);
-    preEncodedPath = preEncodedPath.replace(/\\/g, '/');
-    if (!preEncodedPath.startsWith('file://')) {
-      if (preEncodedPath.startsWith('/')) {
-        preEncodedPath = 'file://' + preEncodedPath;
+    let rawPath: string = fileSystemPath;
+    rawPath = rawPath.replace(/\\/g, '/');
+    if (!rawPath.startsWith('file://')) {
+      if (rawPath.startsWith('/')) {
+        rawPath = 'file://' + rawPath;
       } else {
-        preEncodedPath = 'file:///' + preEncodedPath;
+        rawPath = 'file:///' + rawPath;
       }
     }
-    return new URL(preEncodedPath).toString() as Platform.DevToolsPath.UrlString;
+    return rawPath as Platform.DevToolsPath.UrlString;
   }
 
   static relativePathToUrlString(relativePath: string, baseURL: Platform.DevToolsPath.UrlString):
@@ -188,14 +187,13 @@
     return new URL(preEncodedPath, baseURL).toString() as Platform.DevToolsPath.UrlString;
   }
 
-  static urlToRawPathString(fileURL: Platform.DevToolsPath.UrlString, isWindows?: boolean):
+  static capFilePrefix(fileURL: Platform.DevToolsPath.UrlString, isWindows?: boolean):
       Platform.DevToolsPath.RawPathString {
     console.assert(fileURL.startsWith('file://'), 'This must be a file URL.');
-    const decodedFileURL = decodeURIComponent(fileURL);
     if (isWindows) {
-      return decodedFileURL.substr('file:///'.length).replace(/\//g, '\\') as Platform.DevToolsPath.RawPathString;
+      return fileURL.substr('file:///'.length).replace(/\//g, '\\') as Platform.DevToolsPath.RawPathString;
     }
-    return decodedFileURL.substr('file://'.length) as Platform.DevToolsPath.RawPathString;
+    return fileURL.substr('file://'.length) as Platform.DevToolsPath.RawPathString;
   }
 
   static urlWithoutHash(url: string): string {
diff --git a/front_end/core/sdk/DebuggerModel.ts b/front_end/core/sdk/DebuggerModel.ts
index 5b7727f..59a6532 100644
--- a/front_end/core/sdk/DebuggerModel.ts
+++ b/front_end/core/sdk/DebuggerModel.ts
@@ -425,7 +425,7 @@
     if (this.target().type() === Type.Node && url.startsWith('file://')) {
       // TODO(crbug.com/1253323): Cast to UrlString will be removed when migration to branded types is complete.
       const platformPath =
-          Common.ParsedURL.ParsedURL.urlToRawPathString(url as Platform.DevToolsPath.UrlString, Host.Platform.isWin());
+          Common.ParsedURL.ParsedURL.capFilePrefix(url as Platform.DevToolsPath.UrlString, Host.Platform.isWin());
       urlRegex =
           `${Platform.StringUtilities.escapeForRegExp(platformPath)}|${Platform.StringUtilities.escapeForRegExp(url)}`;
     }
diff --git a/front_end/models/persistence/IsolatedFileSystem.ts b/front_end/models/persistence/IsolatedFileSystem.ts
index 6d27fdc..e8fc84e 100644
--- a/front_end/models/persistence/IsolatedFileSystem.ts
+++ b/front_end/models/persistence/IsolatedFileSystem.ts
@@ -176,7 +176,7 @@
               this.initialGitFoldersInternal.add(parentFolder);
             }
             if (this.isFileExcluded(entry.fullPath + '/')) {
-              this.excludedEmbedderFolders.push(Common.ParsedURL.ParsedURL.urlToRawPathString(
+              this.excludedEmbedderFolders.push(Common.ParsedURL.ParsedURL.capFilePrefix(
                   this.path() + entry.fullPath as Platform.DevToolsPath.UrlString, Host.Platform.isWin()));
               continue;
             }
@@ -555,8 +555,7 @@
 
   tooltipForURL(url: string): string {
     const path = Platform.StringUtilities.trimMiddle(
-        Common.ParsedURL.ParsedURL.urlToRawPathString(url as Platform.DevToolsPath.UrlString, Host.Platform.isWin()),
-        150);
+        Common.ParsedURL.ParsedURL.capFilePrefix(url as Platform.DevToolsPath.UrlString, Host.Platform.isWin()), 150);
     return i18nString(UIStrings.linkedToS, {PH1: path});
   }
 
diff --git a/front_end/models/persistence/PersistenceActions.ts b/front_end/models/persistence/PersistenceActions.ts
index 2ebcc13..23f9b7a 100644
--- a/front_end/models/persistence/PersistenceActions.ts
+++ b/front_end/models/persistence/PersistenceActions.ts
@@ -94,8 +94,8 @@
     const fileURL = binding ? binding.fileSystem.contentURL() : contentProvider.contentURL();
     if (fileURL.startsWith('file://')) {
       // TODO(crbug.com/1253323): Cast to UrlString will be removed when migration to branded types is complete.
-      const path = Common.ParsedURL.ParsedURL.urlToRawPathString(
-          fileURL as Platform.DevToolsPath.UrlString, Host.Platform.isWin());
+      const path =
+          Common.ParsedURL.ParsedURL.capFilePrefix(fileURL as Platform.DevToolsPath.UrlString, Host.Platform.isWin());
       contextMenu.revealSection().appendItem(
           i18nString(UIStrings.openInContainingFolder),
           () => Host.InspectorFrontendHost.InspectorFrontendHostInstance.showItemInFolder(path));
diff --git a/front_end/panels/sources/NavigatorView.ts b/front_end/panels/sources/NavigatorView.ts
index f5abdbd..c8838d9 100644
--- a/front_end/panels/sources/NavigatorView.ts
+++ b/front_end/panels/sources/NavigatorView.ts
@@ -849,7 +849,7 @@
 
     if (project.type() === Workspace.Workspace.projectTypes.FileSystem) {
       // TODO(crbug.com/1253323): Cast to RawPathString will be removed when migration to branded types is complete.
-      const folderPath = Common.ParsedURL.ParsedURL.urlToRawPathString(
+      const folderPath = Common.ParsedURL.ParsedURL.capFilePrefix(
           Persistence.FileSystemWorkspaceBinding.FileSystemWorkspaceBinding.completeURL(project, path) as
               Platform.DevToolsPath.UrlString,
           Host.Platform.isWin());
diff --git a/test/unittests/front_end/core/common/ParsedURL_test.ts b/test/unittests/front_end/core/common/ParsedURL_test.ts
index 4c13da9..699435e 100644
--- a/test/unittests/front_end/core/common/ParsedURL_test.ts
+++ b/test/unittests/front_end/core/common/ParsedURL_test.ts
@@ -121,13 +121,13 @@
 
   it('converts path that starts with "file://" to a platform path', () => {
     const pathTest = 'file://usr/lib' as Platform.DevToolsPath.UrlString;
-    const convertedPath = ParsedURL.urlToRawPathString(pathTest);
+    const convertedPath = ParsedURL.capFilePrefix(pathTest);
     assert.strictEqual(convertedPath, 'usr/lib', 'URL was not converted successfully');
   });
 
   it('converts path that starts with "file:///" to a platform path on Windows', () => {
     const pathTest = 'file:///usr/lib' as Platform.DevToolsPath.UrlString;
-    const convertedPath = ParsedURL.urlToRawPathString(pathTest, true);
+    const convertedPath = ParsedURL.capFilePrefix(pathTest, true);
     assert.strictEqual(convertedPath, 'usr\\lib', 'URL was not converted successfully');
   });
 
@@ -570,33 +570,4 @@
     const convertedUrl = ParsedURL.relativePathToUrlString(relativePath, baseUrl);
     assert.strictEqual(convertedUrl, 'http://localhost:8080/my%20folder/new%20spaced%2520name');
   });
-
-  it('converts URL to a platform path that includes drive letter and spaces on Windows', () => {
-    const urlTest = 'file:///C:/Program%20Files/Google' as Platform.DevToolsPath.UrlString;
-    const convertedUrl = ParsedURL.urlToRawPathString(urlTest, true);
-    assert.strictEqual(convertedUrl, 'C:\\Program Files\\Google', 'URL was not converted successfully');
-  });
-
-  it('converts URL to a platform path that includes spaces and percents', () => {
-    const urlTest = 'file:///home/user/with%20space/with%2520escape' as Platform.DevToolsPath.UrlString;
-    const convertedUrl = ParsedURL.urlToRawPathString(urlTest, false);
-    assert.strictEqual(convertedUrl, '/home/user/with space/with%20escape', 'URL was not converted successfully');
-  });
-
-  it('converts Windows platform path with spaces and percents to file url', () => {
-    const urlTest = 'C:\\Program Files\\with%20escape' as Platform.DevToolsPath.RawPathString;
-    const convertedUrl = ParsedURL.rawPathToUrlString(urlTest);
-    assert.strictEqual(
-        convertedUrl, 'file:///C:/Program%20Files/with%2520escape', 'URL was not converted successfully');
-  });
-
-  it('converts platform path with variety of special characters to URL and back consistently with Chrome', () => {
-    const platformPathTest =
-        '/home/a:b@c(d, e+f)=&g;#h$' as Platform.DevToolsPath.RawPathString;  // Valid filename on unix
-    const urlTest = 'file:///home/a:b@c(d,%20e+f)=&g%3B%23h$' as
-        Platform.DevToolsPath.UrlString;  // URL in Chrome address bar if you open that file
-    assert.strictEqual(ParsedURL.rawPathToUrlString(platformPathTest), urlTest);
-    assert.strictEqual(ParsedURL.urlToRawPathString(urlTest), platformPathTest);
-  });
-
 });
diff --git a/test/unittests/front_end/core/protocol_client/NodeURL_test.ts b/test/unittests/front_end/core/protocol_client/NodeURL_test.ts
index 9d4480e..d2c945b 100644
--- a/test/unittests/front_end/core/protocol_client/NodeURL_test.ts
+++ b/test/unittests/front_end/core/protocol_client/NodeURL_test.ts
@@ -23,16 +23,15 @@
   });
 
   describe('patch', () => {
-    const url = Host.Platform.isWin() ? 'C:\\prog\\foobar.js' : '/usr/local/home/prog/foobar.js';
-    const validPatchedUrl =
-        Host.Platform.isWin() ? 'file:///C:/prog/foobar.js' : 'file:///usr/local/home/prog/foobar.js';
+    const url = Host.Platform.isWin() ? 'c:\\prog\\foobar.js' : '/usr/local/home/prog/foobar.js';
+    const patchedUrl = Host.Platform.isWin() ? 'file:///c:/prog/foobar.js' : 'file:///usr/local/home/prog/foobar.js';
 
     it('does patch url fields', () => {
       const object = {url, result: null};
 
       ProtocolClient.NodeURL.NodeURL.patch(object);
 
-      assert.strictEqual(object.url, validPatchedUrl);
+      assert.strictEqual(object.url, patchedUrl);
     });
 
     it('does not patch the url of the result', () => {
@@ -68,8 +67,8 @@
 
       ProtocolClient.NodeURL.NodeURL.patch(object as unknown as {url: string});
 
-      assert.strictEqual(object.exceptionDetails.url, validPatchedUrl);
-      assert.strictEqual(object.exceptionDetails.stackTrace.callFrames[0].url, validPatchedUrl);
+      assert.strictEqual(object.exceptionDetails.url, patchedUrl);
+      assert.strictEqual(object.exceptionDetails.stackTrace.callFrames[0].url, patchedUrl);
     });
   });
 });