From 72968d53a85a16051052c073df5cb9d1b87a8b0a Mon Sep 17 00:00:00 2001 From: Kim-Adeline Miguel Date: Thu, 13 Jun 2019 15:23:21 -0700 Subject: [PATCH 1/5] Add news file --- news/2 Fixes/5362.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2 Fixes/5362.md diff --git a/news/2 Fixes/5362.md b/news/2 Fixes/5362.md new file mode 100644 index 000000000000..11c7b02f884f --- /dev/null +++ b/news/2 Fixes/5362.md @@ -0,0 +1 @@ +Fix localhost path mappings to lowercase the drive letter on Windows. From a4d7bce4f1a2f8f257d73c19f898a2a17fc48eff Mon Sep 17 00:00:00 2001 From: Kim-Adeline Miguel Date: Thu, 13 Jun 2019 15:25:22 -0700 Subject: [PATCH 2/5] Added unit test --- .../configuration/resolvers/attach.unit.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts b/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts index ab69b32fca3c..3b999e74e53c 100644 --- a/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts +++ b/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts @@ -168,6 +168,23 @@ getNamesAndValues(OSType).forEach(os => { expect(pathMappings![0].localRoot).to.be.equal(workspaceFolder.uri.fsPath); expect(pathMappings![0].remoteRoot).to.be.equal(workspaceFolder.uri.fsPath); }); + + if (os.name === 'Windows') { + test(`Ensure drive letter is lower cased for local path mappings on Windows when host is ${host}`, async () => { + const activeFile = 'xyz.py'; + const workspaceFolder = createMoqWorkspaceFolder('C:/Debug/Python_Path'); + setupActiveEditor(activeFile, PYTHON_LANGUAGE); + const defaultWorkspace = path.join('usr', 'desktop'); + setupWorkspaces([defaultWorkspace]); + + const localRoot = `Debug_PythonPath_${new Date().toString()}`; + const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration); + const pathMappings = (debugConfig as AttachRequestArguments).pathMappings; + const lowercasedLocalRoot = workspaceFolder.uri.fsPath.charAt(0).toLowerCase() + workspaceFolder.uri.fsPath.substr(1); + + expect(pathMappings![0].localRoot).to.be.equal(lowercasedLocalRoot); + }); + } }); ['192.168.1.123', 'don.debugger.com'].forEach(host => { test(`Ensure path mappings are not automatically added when host is '${host}'`, async () => { From b096d3003cbf9dd7735124994934faff8ca08992 Mon Sep 17 00:00:00 2001 From: Kim-Adeline Miguel Date: Thu, 13 Jun 2019 15:25:31 -0700 Subject: [PATCH 3/5] Actual fix --- .../debugger/extension/configuration/resolvers/attach.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/client/debugger/extension/configuration/resolvers/attach.ts b/src/client/debugger/extension/configuration/resolvers/attach.ts index 0f67c89b6b5a..6e5bd6c5ef1c 100644 --- a/src/client/debugger/extension/configuration/resolvers/attach.ts +++ b/src/client/debugger/extension/configuration/resolvers/attach.ts @@ -96,8 +96,14 @@ export class AttachConfigurationResolver extends BaseConfigurationResolver= 0) { + // If on Windows, lowercase the drive letter for path mappings. + let localRoot = workspaceFolder.fsPath; + if (this.platformService.isWindows && localRoot.match(/^[A-Z]:/)) { + localRoot = `${localRoot[0].toLowerCase()}${localRoot.substr(1)}`; + } + debugConfiguration.pathMappings!.push({ - localRoot: workspaceFolder.fsPath, + localRoot, remoteRoot: workspaceFolder.fsPath }); } From d1026f0cfea7b8b68af414cbb275182a6a89c70a Mon Sep 17 00:00:00 2001 From: Kim-Adeline Miguel Date: Fri, 14 Jun 2019 08:48:28 -0700 Subject: [PATCH 4/5] Add tests and use path.join --- .../resolvers/attach.unit.test.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts b/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts index 3b999e74e53c..51a2b35eee7f 100644 --- a/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts +++ b/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts @@ -170,9 +170,9 @@ getNamesAndValues(OSType).forEach(os => { }); if (os.name === 'Windows') { - test(`Ensure drive letter is lower cased for local path mappings on Windows when host is ${host}`, async () => { + test(`Ensure drive letter is lower cased for local path mappings on Windows when host is '${host}'`, async () => { const activeFile = 'xyz.py'; - const workspaceFolder = createMoqWorkspaceFolder('C:/Debug/Python_Path'); + const workspaceFolder = createMoqWorkspaceFolder(path.join('C:', 'Debug', 'Python_Path')); setupActiveEditor(activeFile, PYTHON_LANGUAGE); const defaultWorkspace = path.join('usr', 'desktop'); setupWorkspaces([defaultWorkspace]); @@ -184,6 +184,33 @@ getNamesAndValues(OSType).forEach(os => { expect(pathMappings![0].localRoot).to.be.equal(lowercasedLocalRoot); }); + test(`Ensure local path mappings are not modified when not pointing to a local drive when host is '${host}'`, async () => { + const activeFile = 'xyz.py'; + const workspaceFolder = createMoqWorkspaceFolder(path.join('Server', 'Debug', 'Python_Path')); + setupActiveEditor(activeFile, PYTHON_LANGUAGE); + const defaultWorkspace = path.join('usr', 'desktop'); + setupWorkspaces([defaultWorkspace]); + + const localRoot = `Debug_PythonPath_${new Date().toString()}`; + const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration); + const pathMappings = (debugConfig as AttachRequestArguments).pathMappings; + + expect(pathMappings![0].localRoot).to.be.equal(workspaceFolder.uri.fsPath); + }); + } else { + test(`Ensure local path mappings are not modified and when host is '${host}'`, async () => { + const activeFile = 'xyz.py'; + const workspaceFolder = createMoqWorkspaceFolder(path.join('C:', 'Debug', 'Python_Path')); + setupActiveEditor(activeFile, PYTHON_LANGUAGE); + const defaultWorkspace = path.join('usr', 'desktop'); + setupWorkspaces([defaultWorkspace]); + + const localRoot = `Debug_PythonPath_${new Date().toString()}`; + const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration); + const pathMappings = (debugConfig as AttachRequestArguments).pathMappings; + + expect(pathMappings![0].localRoot).to.be.equal(workspaceFolder.uri.fsPath); + }); } }); ['192.168.1.123', 'don.debugger.com'].forEach(host => { From 581ffe13b64f592fa1f1766a543fa3a94040ef77 Mon Sep 17 00:00:00 2001 From: Kim-Adeline Miguel Date: Fri, 14 Jun 2019 09:13:36 -0700 Subject: [PATCH 5/5] Move Windows condition inside test (else skip) --- .../resolvers/attach.unit.test.ts | 74 ++++++++----------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts b/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts index 51a2b35eee7f..17850cfa5fd2 100644 --- a/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts +++ b/src/test/debugger/extension/configuration/resolvers/attach.unit.test.ts @@ -169,49 +169,37 @@ getNamesAndValues(OSType).forEach(os => { expect(pathMappings![0].remoteRoot).to.be.equal(workspaceFolder.uri.fsPath); }); - if (os.name === 'Windows') { - test(`Ensure drive letter is lower cased for local path mappings on Windows when host is '${host}'`, async () => { - const activeFile = 'xyz.py'; - const workspaceFolder = createMoqWorkspaceFolder(path.join('C:', 'Debug', 'Python_Path')); - setupActiveEditor(activeFile, PYTHON_LANGUAGE); - const defaultWorkspace = path.join('usr', 'desktop'); - setupWorkspaces([defaultWorkspace]); - - const localRoot = `Debug_PythonPath_${new Date().toString()}`; - const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration); - const pathMappings = (debugConfig as AttachRequestArguments).pathMappings; - const lowercasedLocalRoot = workspaceFolder.uri.fsPath.charAt(0).toLowerCase() + workspaceFolder.uri.fsPath.substr(1); - - expect(pathMappings![0].localRoot).to.be.equal(lowercasedLocalRoot); - }); - test(`Ensure local path mappings are not modified when not pointing to a local drive when host is '${host}'`, async () => { - const activeFile = 'xyz.py'; - const workspaceFolder = createMoqWorkspaceFolder(path.join('Server', 'Debug', 'Python_Path')); - setupActiveEditor(activeFile, PYTHON_LANGUAGE); - const defaultWorkspace = path.join('usr', 'desktop'); - setupWorkspaces([defaultWorkspace]); - - const localRoot = `Debug_PythonPath_${new Date().toString()}`; - const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration); - const pathMappings = (debugConfig as AttachRequestArguments).pathMappings; - - expect(pathMappings![0].localRoot).to.be.equal(workspaceFolder.uri.fsPath); - }); - } else { - test(`Ensure local path mappings are not modified and when host is '${host}'`, async () => { - const activeFile = 'xyz.py'; - const workspaceFolder = createMoqWorkspaceFolder(path.join('C:', 'Debug', 'Python_Path')); - setupActiveEditor(activeFile, PYTHON_LANGUAGE); - const defaultWorkspace = path.join('usr', 'desktop'); - setupWorkspaces([defaultWorkspace]); - - const localRoot = `Debug_PythonPath_${new Date().toString()}`; - const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration); - const pathMappings = (debugConfig as AttachRequestArguments).pathMappings; - - expect(pathMappings![0].localRoot).to.be.equal(workspaceFolder.uri.fsPath); - }); - } + test(`Ensure drive letter is lower cased for local path mappings on Windows when host is '${host}'`, async function () { + if (os.name !== 'Windows') { + return this.skip(); + } + + const activeFile = 'xyz.py'; + const workspaceFolder = createMoqWorkspaceFolder(path.join('C:', 'Debug', 'Python_Path')); + setupActiveEditor(activeFile, PYTHON_LANGUAGE); + const defaultWorkspace = path.join('usr', 'desktop'); + setupWorkspaces([defaultWorkspace]); + + const localRoot = `Debug_PythonPath_${new Date().toString()}`; + const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration); + const pathMappings = (debugConfig as AttachRequestArguments).pathMappings; + const lowercasedLocalRoot = workspaceFolder.uri.fsPath.charAt(0).toLowerCase() + workspaceFolder.uri.fsPath.substr(1); + + expect(pathMappings![0].localRoot).to.be.equal(lowercasedLocalRoot); + }); + test(`Ensure local path mappings are not modified when not pointing to a local drive when host is '${host}'`, async () => { + const activeFile = 'xyz.py'; + const workspaceFolder = createMoqWorkspaceFolder(path.join('Server', 'Debug', 'Python_Path')); + setupActiveEditor(activeFile, PYTHON_LANGUAGE); + const defaultWorkspace = path.join('usr', 'desktop'); + setupWorkspaces([defaultWorkspace]); + + const localRoot = `Debug_PythonPath_${new Date().toString()}`; + const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { localRoot, host, request: 'attach' } as any as DebugConfiguration); + const pathMappings = (debugConfig as AttachRequestArguments).pathMappings; + + expect(pathMappings![0].localRoot).to.be.equal(workspaceFolder.uri.fsPath); + }); }); ['192.168.1.123', 'don.debugger.com'].forEach(host => { test(`Ensure path mappings are not automatically added when host is '${host}'`, async () => {