mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-30 09:54:02 +08:00
Revert "Add special character encoding and decoding to conversions"
This reverts commit a89353f5ce.
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>
This commit is contained in:
committed by
Devtools-frontend LUCI CQ
parent
df63e266a6
commit
0177fa7791
@@ -168,17 +168,16 @@ export class ParsedURL {
|
||||
}
|
||||
|
||||
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 @@ export class ParsedURL {
|
||||
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 {
|
||||
|
||||
@@ -425,7 +425,7 @@ export class DebuggerModel extends SDKModel<EventTypes> {
|
||||
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)}`;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ export class IsolatedFileSystem extends PlatformFileSystem {
|
||||
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 @@ export class IsolatedFileSystem extends PlatformFileSystem {
|
||||
|
||||
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});
|
||||
}
|
||||
|
||||
|
||||
@@ -94,8 +94,8 @@ export class ContextMenuProvider implements UI.ContextMenu.Provider {
|
||||
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));
|
||||
|
||||
@@ -849,7 +849,7 @@ export class NavigatorView extends UI.Widget.VBox implements SDK.TargetManager.O
|
||||
|
||||
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());
|
||||
|
||||
@@ -121,13 +121,13 @@ describe('Parsed URL', () => {
|
||||
|
||||
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 @@ describe('Parsed URL', () => {
|
||||
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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -23,16 +23,15 @@ describe('NodeURL', () => {
|
||||
});
|
||||
|
||||
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 @@ describe('NodeURL', () => {
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user