Skip to content

Commit

Permalink
never convert relative paths to URIs; fixes #60667
Browse files Browse the repository at this point in the history
  • Loading branch information
weinand committed Oct 17, 2018
1 parent f0101b0 commit 48adb20
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 33 deletions.
17 changes: 3 additions & 14 deletions src/vs/workbench/api/electron-browser/mainThreadDebugService.ts
Expand Up @@ -14,9 +14,8 @@ import {
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import severity from 'vs/base/common/severity';
import { AbstractDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter';
import * as paths from 'vs/base/common/paths';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { convertToVSCPaths, convertToDAPaths } from 'vs/workbench/parts/debug/common/debugUtils';
import { convertToVSCPaths, convertToDAPaths, stringToUri, uriToString } from 'vs/workbench/parts/debug/common/debugUtils';
import { deepClone } from 'vs/base/common/objects';


Expand Down Expand Up @@ -215,11 +214,7 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb

public $acceptDAMessage(handle: number, message: DebugProtocol.ProtocolMessage) {

convertToVSCPaths(message, source => {
if (typeof source.path === 'object') {
source.path = uri.revive(source.path).toString();
}
});
convertToVSCPaths(message, source => uriToString(source));

this._debugAdapters.get(handle).acceptMessage(message);
}
Expand Down Expand Up @@ -302,13 +297,7 @@ class ExtensionHostDebugAdapter extends AbstractDebugAdapter {
// since we modify Source.paths in the message in place, we need to make a copy of it (see #61129)
const msg = deepClone(message);

convertToDAPaths(msg, source => {
if (paths.isAbsolute(source.path)) {
(<any>source).path = uri.file(source.path);
} else {
(<any>source).path = uri.parse(source.path);
}
});
convertToDAPaths(msg, source => stringToUri(source));

this._proxy.$sendDAMessage(this._handle, msg);
}
Expand Down
14 changes: 3 additions & 11 deletions src/vs/workbench/api/node/extHostDebugService.ts
Expand Up @@ -27,7 +27,7 @@ import { getTerminalLauncher, hasChildprocesses, prepareCommand } from 'vs/workb
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { AbstractVariableResolverService } from 'vs/workbench/services/configurationResolver/node/variableResolver';
import { ExtHostConfiguration } from './extHostConfiguration';
import { convertToVSCPaths, convertToDAPaths } from 'vs/workbench/parts/debug/common/debugUtils';
import { convertToVSCPaths, convertToDAPaths, stringToUri, uriToString } from 'vs/workbench/parts/debug/common/debugUtils';
import { ExtHostTerminalService } from 'vs/workbench/api/node/extHostTerminalService';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
Expand Down Expand Up @@ -400,11 +400,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape {
}

// DA -> VS Code
convertToVSCPaths(msg, source => {
if (paths.isAbsolute(source.path)) {
(<any>source).path = URI.file(source.path);
}
});
convertToVSCPaths(msg, source => stringToUri(source));

mythis._debugServiceProxy.$acceptDAMessage(handle, msg);
});
Expand Down Expand Up @@ -435,11 +431,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape {

public $sendDAMessage(handle: number, message: DebugProtocol.ProtocolMessage): TPromise<void> {
// VS Code -> DA
convertToDAPaths(message, source => {
if (typeof source.path === 'object') {
source.path = URI.revive(source.path).fsPath;
}
});
convertToDAPaths(message, source => uriToString(source));

const tracker = this._debugAdaptersTrackers.get(handle);
if (tracker) {
Expand Down
23 changes: 15 additions & 8 deletions src/vs/workbench/parts/debug/common/debugSource.ts
Expand Up @@ -12,6 +12,7 @@ import { DEBUG_SCHEME } from 'vs/workbench/parts/debug/common/debug';
import { IRange } from 'vs/editor/common/core/range';
import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { Schemas } from 'vs/base/common/network';
import { isUri } from 'vs/workbench/parts/debug/common/debugUtils';

const UNKNOWN_SOURCE_LABEL = nls.localize('unknownSource', "Unknown Source");

Expand All @@ -36,23 +37,29 @@ export class Source {

constructor(public raw: DebugProtocol.Source, sessionId: string) {
let path: string;
if (!raw) {
if (raw) {
path = this.raw.path || this.raw.name;
this.available = true;
} else {
this.raw = { name: UNKNOWN_SOURCE_LABEL };
this.available = false;
path = `${DEBUG_SCHEME}:${UNKNOWN_SOURCE_LABEL}`;
} else {
path = this.raw.path || this.raw.name;
this.available = true;
}

if (this.raw.sourceReference > 0) {
this.uri = uri.parse(`${DEBUG_SCHEME}:${encodeURIComponent(path)}?session=${encodeURIComponent(sessionId)}&ref=${this.raw.sourceReference}`);
} else {
if (paths.isAbsolute(path)) {
this.uri = uri.file(path);
} else {
// assume that path is a URI
if (isUri(path)) {
this.uri = uri.parse(path);
} else {
// assume path
if (paths.isAbsolute_posix(path) || paths.isAbsolute_win32(path)) {
this.uri = uri.file(path);
} else {
// path is relative
// should not happen because relative paths always have a sourceReference > 0
console.error('cannot handle relative paths without sourceReference');
}
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions src/vs/workbench/parts/debug/common/debugUtils.ts
Expand Up @@ -5,6 +5,8 @@

import { equalsIgnoreCase } from 'vs/base/common/strings';
import { IConfig } from 'vs/workbench/parts/debug/common/debug';
import { URI as uri } from 'vs/base/common/uri';
import { isAbsolute_posix, isAbsolute_win32 } from 'vs/base/common/paths';

const _formatPIIRegexp = /{([^}]+)}/g;

Expand Down Expand Up @@ -67,6 +69,41 @@ export function getExactExpressionStartAndEnd(lineContent: string, looseStart: n
{ start: 0, end: 0 };
}

// RFC 2396, Appendix A: https://www.ietf.org/rfc/rfc2396.txt
const _schemePattern = /^[a-zA-Z][a-zA-Z0-9\+\-\.]+:/;

export function isUri(s: string) {
// heuristics: a valid uri starts with a scheme and
// the scheme has at least 2 characters so that it doesn't look like a drive letter.
return s && s.match(_schemePattern);
}

export function stringToUri(source: DebugProtocol.Source): void {
if (typeof source.path === 'string') {
if (isUri(source.path)) {
(<any>source).path = uri.parse(source.path);
} else {
// assume path
if (isAbsolute_posix(source.path) || isAbsolute_win32(source.path)) {
(<any>source).path = uri.file(source.path);
} else {
// leave relative path as is
}
}
}
}

export function uriToString(source: DebugProtocol.Source): void {
if (typeof source.path === 'object') {
const u = uri.revive(source.path);
if (u.scheme === 'file') {
source.path = u.fsPath;
} else {
source.path = u.toString();
}
}
}

// path hooks helpers

export function convertToDAPaths(msg: DebugProtocol.ProtocolMessage, fixSourcePaths: (source: DebugProtocol.Source) => void): void {
Expand Down

0 comments on commit 48adb20

Please sign in to comment.