@@ -8,6 +8,16 @@ import * as url from 'url';
88import * as path from 'path' ;
99import * as util from 'util' ;
1010
11+ /** converts a path to a file URI */
12+ function fileUrl ( path : string ) : string {
13+ let pathName = path . replace ( / \\ / g, '/' ) ;
14+ // Windows drive letter must be prefixed with a slash
15+ if ( pathName [ 0 ] !== '/' ) {
16+ pathName = '/' + pathName ;
17+ }
18+ return encodeURI ( 'file://' + pathName ) ;
19+ }
20+
1121/** formats a xdebug property value for VS Code */
1222function formatPropertyValue ( property : xdebug . BaseProperty ) : string {
1323 let displayValue : string ;
@@ -221,17 +231,21 @@ class PhpDebugSession extends vscode.DebugSession {
221231
222232 /** converts a local path from VS Code to a server-side XDebug file URI with respect to source root settings */
223233 protected convertClientPathToDebugger ( localPath : string ) : string {
224- let localFileUri = localPath . replace ( / \\ / g, '/' ) ;
225- if ( localFileUri [ 0 ] !== '/' ) {
226- localFileUri = '/' + localFileUri ;
227- }
228- localFileUri = encodeURI ( 'file://' + localFileUri ) ;
234+ let localFileUri = fileUrl ( localPath ) ;
229235 let serverFileUri : string ;
230236 if ( this . _args . serverSourceRoot && this . _args . localSourceRoot ) {
237+ let localSourceRootUrl = fileUrl ( this . _args . localSourceRoot ) ;
238+ if ( ! localSourceRootUrl . endsWith ( '/' ) ) {
239+ localSourceRootUrl += '/' ;
240+ }
241+ let serverSourceRootUrl = fileUrl ( this . _args . serverSourceRoot ) ;
242+ if ( ! serverSourceRootUrl . endsWith ( '/' ) ) {
243+ serverSourceRootUrl += '/' ;
244+ }
231245 // get the part of the path that is relative to the source root
232- const urlRelativeToSourceRoot = urlRelative ( this . _args . localSourceRoot , localFileUri ) ;
246+ const urlRelativeToSourceRoot = urlRelative ( localSourceRootUrl , localFileUri ) ;
233247 // resolve from the server source root
234- serverFileUri = url . resolve ( this . _args . serverSourceRoot , urlRelativeToSourceRoot ) ;
248+ serverFileUri = url . resolve ( serverSourceRootUrl , urlRelativeToSourceRoot ) ;
235249 } else {
236250 serverFileUri = localFileUri ;
237251 }
0 commit comments