From 34d611d313b856d0a07a8c41ced684827ceb7e54 Mon Sep 17 00:00:00 2001 From: Damjan Cvetko Date: Wed, 14 Apr 2021 10:03:25 +0200 Subject: [PATCH] fix: Properly process windows UNC paths. --- CHANGELOG.md | 11 +++++++++++ src/paths.ts | 11 +++++++---- src/test/paths.ts | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..164cd874 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Change Log + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). + +## [1.14.13] + +### Fixed + +- Handle windows UNC paths without mapping. diff --git a/src/paths.ts b/src/paths.ts index 6fa00011..7f5ee6fc 100644 --- a/src/paths.ts +++ b/src/paths.ts @@ -31,12 +31,12 @@ export function convertDebuggerPathToClient( let localSourceRoot: string | undefined let serverSourceRoot: string | undefined if (typeof fileUri === 'string') { - fileUri = url.parse(fileUri) + fileUri = url.parse(fileUri, false, true) } // convert the file URI to a path - let serverPath = decode(fileUri.pathname!) + let serverPath = decode((fileUri.host ? '///' + fileUri.host : '') + fileUri.pathname!) // strip the trailing slash from Windows paths (indicated by a drive letter with a colon) - const serverIsWindows = /^\/[a-zA-Z]:\//.test(serverPath) + const serverIsWindows = /^\/[a-zA-Z]:\//.test(serverPath) || /^\/\/\//.test(serverPath) if (serverIsWindows) { serverPath = serverPath.substr(1) } @@ -92,6 +92,9 @@ export function convertClientPathToDebugger(localPath: string, pathMapping?: { [ localPath.replace(/^[A-Z]:\\/, match => match.toLowerCase()), { resolve: false } ) + if (/^file:\/\/\/\//.test(localFileUri)) { + localFileUri = localFileUri.replace(/^file:\/\/\/\//, 'file://') + } let serverFileUri: string if (pathMapping) { for (const mappedServerPath of Object.keys(pathMapping)) { @@ -142,7 +145,7 @@ export function convertClientPathToDebugger(localPath: string, pathMapping?: { [ } function isWindowsUri(path: string): boolean { - return /^file:\/\/\/[a-zA-Z]:\//.test(path) + return /^file:\/\/\/[a-zA-Z]:\//.test(path) || /^file:\/\/[^\/]/.test(path) } export function isSameUri(clientUri: string, debuggerUri: string): boolean { diff --git a/src/test/paths.ts b/src/test/paths.ts index d1696bec..074327e3 100644 --- a/src/test/paths.ts +++ b/src/test/paths.ts @@ -32,6 +32,12 @@ describe('paths', () => { 'file:///c:/Users/felix/test.php' ) }) + it('should convert a windows UNC path to a URI', () => { + assert.strictEqual( + convertClientPathToDebugger('\\\\server\\Users\\felix\\test.php'), + 'file://server/Users/felix/test.php' + ) + }) it('should convert a unix path to a URI', () => { assert.equal(convertClientPathToDebugger('/home/felix/test.php'), 'file:///home/felix/test.php') }) @@ -182,6 +188,24 @@ describe('paths', () => { 'd:\\arx iT\\2-Réalisation\\mmi\\V1.0\\Web\\core\\header.php' ) }) + it('should convert windows UNC URI to windows UNC path', () => { + assert.strictEqual( + convertDebuggerPathToClient('file://WSL/Ubuntu/home/zobo/php/test1.php'), + '\\\\wsl\\Ubuntu\\home\\zobo\\php\\test1.php' + ) + }) + it('should convert windows UNC URI to windows UNC path with $ in host', () => { + assert.strictEqual( + convertDebuggerPathToClient('file://WSL%24/Ubuntu/home/zobo/php/test1.php'), + '\\\\wsl$\\Ubuntu\\home\\zobo\\php\\test1.php' + ) + }) + it('should convert windows UNC URI to windows UNC path with $ in path', () => { + assert.strictEqual( + convertDebuggerPathToClient('file://SERVER/C$/home/zobo/php/test1.php'), + '\\\\server\\C$\\home\\zobo\\php\\test1.php' + ) + }) }) describe('with source mapping', () => { // unix to unix