Make sure we handle loading of markdown resources from UNC workspace correctly

Fixes #48403
This commit is contained in:
Matt Bierner
2019-07-09 15:52:08 -07:00
parent 2f05851c49
commit 4c07744817
3 changed files with 49 additions and 20 deletions

View File

@@ -9,4 +9,25 @@ export interface WebviewResourceProvider {
toWebviewResource(resource: vscode.Uri): vscode.Uri;
readonly cspSource: string;
}
export function normalizeResource(
base: vscode.Uri,
resource: vscode.Uri
): vscode.Uri {
// If we have a windows path and are loading a workspace with an authority,
// make sure we use a unc path with an explicit localhost authority.
//
// Otherwise, the `<base>` rule will insert the authority into the resolved resource
// URI incorrectly.
if (base.authority && !resource.authority) {
const driveMatch = resource.path.match(/^\/(\w):\//);
if (driveMatch) {
return vscode.Uri.file(`\\\\localhost\\${driveMatch[1]}$\\${resource.fsPath.replace(/^\w:\\/, '')}`).with({
fragment: resource.fragment,
query: resource.query
});
}
}
return resource;
}